Version Description
Download this release
Release Info
Developer | businessdirectoryplugin |
Plugin | Business Directory Plugin |
Version | 3.5.4 |
Comparing to | |
See all releases |
Version 3.5.4
- README.TXT +880 -0
- admin/admin-pages.php +19 -0
- admin/class-admin-listings.php +330 -0
- admin/class-admin.php +853 -0
- admin/class-listing-fields-metabox.php +66 -0
- admin/css/listing-metabox.css +131 -0
- admin/css/listing-metabox.min.css +1 -0
- admin/csv-export.php +403 -0
- admin/csv-import.php +685 -0
- admin/fees.php +191 -0
- admin/form-fields.php +271 -0
- admin/index.php +1 -0
- admin/js/listing.js +40 -0
- admin/js/listing.min.js +1 -0
- admin/listing-metabox.php +117 -0
- admin/page-debug.php +111 -0
- admin/payments.php +32 -0
- admin/resources/2checkout-gateway-module.png +0 -0
- admin/resources/admin.css +773 -0
- admin/resources/admin.js +730 -0
- admin/resources/admin.min.css +1 -0
- admin/resources/admin.min.js +1 -0
- admin/resources/check.png +0 -0
- admin/resources/drag-handle.png +0 -0
- admin/resources/export.css +19 -0
- admin/resources/export.js +136 -0
- admin/resources/export.min.css +1 -0
- admin/resources/export.min.js +1 -0
- admin/resources/manual-upgrade.js +42 -0
- admin/resources/manual-upgrade.min.js +1 -0
- admin/resources/menuico.png +0 -0
- admin/resources/new.gif +0 -0
- admin/resources/payfast-payment-module.png +0 -0
- admin/resources/paypal-gateway-module.png +0 -0
- admin/resources/stripe-payment-module.png +0 -0
- admin/templates/csv-export.tpl.php +170 -0
- admin/templates/csv-import.tpl.php +203 -0
- admin/templates/debug-info.tpl.php +33 -0
- admin/templates/fees-addoredit.tpl.php +137 -0
- admin/templates/fees-confirm-delete.tpl.php +17 -0
- admin/templates/fees.tpl.php +89 -0
- admin/templates/form-fields-addoredit.tpl.php +191 -0
- admin/templates/form-fields-confirm-delete.tpl.php +17 -0
- admin/templates/form-fields.tpl.php +14 -0
- admin/templates/header.tpl.php +16 -0
- admin/templates/home.tpl.php +49 -0
- admin/templates/listing-change-fee.tpl.php +31 -0
- admin/templates/listing-metabox-categories.tpl.php +126 -0
- admin/templates/listing-metabox-fees.tpl.php +23 -0
- admin/templates/listing-metabox-feesummary.tpl.php +13 -0
- admin/templates/listing-metabox-transactions.tpl.php +34 -0
- admin/templates/payment-details.tpl.php +59 -0
- admin/templates/settings.tpl.php +60 -0
- admin/templates/sidebar.tpl.php +92 -0
- admin/templates/transactions.tpl.php +9 -0
- admin/templates/uninstall-capture-form.tpl.php +38 -0
- admin/templates/uninstall-complete.tpl.php +12 -0
- admin/templates/uninstall-confirm.tpl.php +9 -0
- admin/tracking.php +238 -0
- admin/transactions.php +278 -0
- business-directory-plugin.php +1578 -0
- core/api.php +359 -0
- core/class-ajax-response.php +42 -0
- core/class-db-model.php +357 -0
- core/class-email.php +94 -0
- core/class-form-field-type.php +342 -0
- core/class-form-field.php +614 -0
- core/class-gateway.php +65 -0
- core/class-listing-upgrade-api.php +224 -0
- core/class-listing.php +589 -0
- core/class-listings-api.php +844 -0
- core/class-listings-widget.php +153 -0
- core/class-page-meta.php +70 -0
- core/class-payment.php +430 -0
- core/class-settings.php +1258 -0
- core/class-view.php +21 -0
- core/class-wpbdp.php +6 -0
- core/compatibility/class-compat.php +17 -0
- core/compatibility/class-wpml-compat.php +163 -0
- core/compatibility/deprecated.php +354 -0
- core/compatibility/templates/businessdirectory-category.tpl.php +19 -0
- core/compatibility/templates/businessdirectory-single.tpl.php +10 -0
- core/compatibility/templates/wpbusdirman-index-categories.php +22 -0
- core/css/debug.css +76 -0
- core/css/debug.min.css +1 -0
- core/css/dnd-upload.css +59 -0
- core/css/dnd-upload.min.css +1 -0
- core/css/widgets.css +17 -0
- core/css/widgets.min.css +1 -0
- core/css/wpbdp-legacy.css +187 -0
- core/css/wpbdp-legacy.min.css +1 -0
- core/css/wpbdp.css +559 -0
- core/css/wpbdp.min.css +1 -0
- core/debugging.php +224 -0
- core/form-fields-types.php +1051 -0
- core/form-fields.php +550 -0
- core/gateways-dummy.php +74 -0
- core/gateways-googlewallet.php +312 -0
- core/images/default-image-big.gif +0 -0
- core/images/default.png +0 -0
- core/images/featuredlisting.png +0 -0
- core/images/googlewallet.gif +0 -0
- core/index.php +1 -0
- core/installer.php +794 -0
- core/js/debug.js +27 -0
- core/js/debug.min.js +1 -0
- core/js/dnd-upload.js +70 -0
- core/js/dnd-upload.min.js +1 -0
- core/js/googlewallet.js +24 -0
- core/js/googlewallet.min.js +1 -0
- core/js/wpbdp.js +171 -0
- core/js/wpbdp.min.js +1 -0
- core/licensing.php +385 -0
- core/listings.php +5 -0
- core/payment.php +668 -0
- core/seo.php +39 -0
- core/templates-generic.php +112 -0
- core/templates-listings.php +202 -0
- core/templates-ui.php +467 -0
- core/utils.php +495 -0
- core/view-checkout.php +151 -0
- core/view-delete-listing.php +39 -0
- core/view-listing-contact.php +188 -0
- core/view-manage-recurring.php +101 -0
- core/view-renew-listing.php +136 -0
- core/view-submit-listing.php +576 -0
- core/view-upgrade-listing.php +63 -0
- core/views.php +466 -0
- core/widget-featured-listings.php +44 -0
- core/widget-latest-listings.php +25 -0
- core/widget-random-listings.php +24 -0
- core/widget-search.php +108 -0
- index.php +1 -0
- languages/WPBDM-en_US.mo +0 -0
- languages/WPBDM-en_US.po +524 -0
README.TXT
ADDED
@@ -0,0 +1,880 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Business Directory Plugin ===
|
2 |
+
Contributors: businessdirectoryplugin
|
3 |
+
Donate link: http://businessdirectoryplugin.com/premium-modules/
|
4 |
+
Tags: wordpress directory,wordpress directory plugin, wordpress directory theme,wordpress business directory,business directory,classified ads,classifieds,directory plugin,business directory plugin,directory widget,church directory,address book,address,member directory,members directory,city portal,city portal plugin,city guide plugin,city guide
|
5 |
+
Requires at least: 3.7
|
6 |
+
Tested up to: 4.1
|
7 |
+
Last Updated: 2015-Jan-6
|
8 |
+
Stable tag: tags/3.5.4
|
9 |
+
License: GPLv2 or later
|
10 |
+
|
11 |
+
Build local directories, business provider listings, Yellow-Pages directories, Yelp-like review sections and much more!
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
[Main Site](http://businessdirectoryplugin.com/) | [Support Forum](http://businessdirectoryplugin.com/support-forum/) | [Documentation](http://businessdirectoryplugin.com/docs/) | [Showcase](http://businessdirectoryplugin.com/showcase/) | [Premium Modules](http://businessdirectoryplugin.com/premium-modules/)
|
16 |
+
|
17 |
+
Business Directory Plugin is the most popular, widely-used, and best-supported WordPress Business Directory plugin available. Increase interaction on your website, improve customer retention and a add revenue-generating section to your site with Business Directory Plugin!
|
18 |
+
|
19 |
+
Business Directory Plugin allows you to build local directories, business provider listings, Yellow-Pages style business directories, Yelp-like review sections, create a church directory, build an address book and much more. You can add any kind of directory using Business Directory plugin.
|
20 |
+
|
21 |
+
= Features =
|
22 |
+
* Fully customizable form fields
|
23 |
+
* Accept payment for listings OR have free listings
|
24 |
+
* Full support for recurring payments (PayPal, Wallet, Stripe)
|
25 |
+
* Allow for featured/sticky listings for an upgrade fee
|
26 |
+
* Create multiple fee plans, which can be assigned to categories for posting
|
27 |
+
* Built in CSV import and export
|
28 |
+
* Support for reCAPTCHA to avoid spam listings
|
29 |
+
* Users who post can edit listings without access to WP dashboard
|
30 |
+
* SEO Friendly using Yoast SEO
|
31 |
+
* Configurable quick-search field and sorting bar for listings
|
32 |
+
* Rate businesses in your directory (now with Microformat support) (using the Ratings Module)
|
33 |
+
* Display the location of the business (categories, search, details--now with custom map sizes) (using the Google Maps Module)
|
34 |
+
* Location based result filtering (using the Regions Module)
|
35 |
+
* ZIP code radius searches (using the ZIP Search Module)
|
36 |
+
* Assign features to paid or sticky listing plans to give users incentive to upgrade (using the Featured levels module)
|
37 |
+
* Allow users to upload PDFs (using the File Upload Module) (NEW!)
|
38 |
+
* Display Category Icons/Allow Parent-Child Category Navigation (using the Enhanced Category Module)
|
39 |
+
* Manage attachments on listings (using the Attachments module, supports PDF, Text files, images)
|
40 |
+
* Accept payments using Stripe (using the Stripe Gateway Module) (NEW!)
|
41 |
+
* Accept payments using PayFast (using the PayFast Gateway Module) (NEW!)
|
42 |
+
|
43 |
+
For a complete and detailed list of features, please visit: http://businessdirectoryplugin.com/features/
|
44 |
+
|
45 |
+
Please report any bugs you find via http://businessdirectoryplugin.com/support-forum/
|
46 |
+
|
47 |
+
= Premium Module Links: =
|
48 |
+
These are optional modules that you can use to enhance Business Directory Plugin's functionality and
|
49 |
+
support future development:
|
50 |
+
|
51 |
+
NEW! [PayFast Gateway Module](http://businessdirectoryplugin.com/downloads/payfast-payment-module/?ref=wp)
|
52 |
+
|
53 |
+
NEW! [Stripe Gateway Module](http://businessdirectoryplugin.com/downloads/stripe-payment-module/?ref=wp)
|
54 |
+
|
55 |
+
NEW! [File Upload Module](http://businessdirectoryplugin.com/downloads/file-attachments-module/?ref=wp)
|
56 |
+
|
57 |
+
[Featured Levels Module](http://businessdirectoryplugin.com/downloads/featured-levels-module/?ref=wp)
|
58 |
+
|
59 |
+
[ZIP Code Search Module](http://businessdirectoryplugin.com/downloads/zip-search-module/?ref=wp)
|
60 |
+
|
61 |
+
[Regions Module](http://businessdirectoryplugin.com/downloads/regions-module/?ref=wp)
|
62 |
+
|
63 |
+
[Ratings Module](http://businessdirectoryplugin.com/downloads/ratings-module/?ref=wp)
|
64 |
+
|
65 |
+
[Google Maps Module](http://businessdirectoryplugin.com/downloads/google-maps-module/?ref=wp)
|
66 |
+
|
67 |
+
[PayPal Gateway Module](http://businessdirectoryplugin.com/downloads/paypal-gateway-module/?ref=wp)
|
68 |
+
|
69 |
+
[2Checkout Gateway Module](http://businessdirectoryplugin.com/downloads/2checkout-gateway-module/?ref=wp)
|
70 |
+
|
71 |
+
For more information and support please visit [http://businessdirectoryplugin.com](http://businessdirectoryplugin.com?ref=wp)
|
72 |
+
For plugin support please visit [http://businessdirectoryplugin.com/forums](http://businessdirectoryplugin.com/forums)
|
73 |
+
|
74 |
+
If you love the plugin, [please consider purchasing a Premium Module](http://businessdirectoryplugin.com/premium-modules/?ref=wp)!
|
75 |
+
|
76 |
+
|
77 |
+
== Credits ==
|
78 |
+
Copyright 2009-15, Dave Rodenbaugh
|
79 |
+
Original Author: A. Lewis
|
80 |
+
|
81 |
+
This program is free software; you can redistribute it and/or modify
|
82 |
+
it under the terms of the GNU General Public License as published by
|
83 |
+
the Free Software Foundation; either version 2 of the License, or
|
84 |
+
(at your option) any later version.
|
85 |
+
|
86 |
+
This program is distributed in the hope that it will be useful,
|
87 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
88 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
89 |
+
GNU General Public License for more details.
|
90 |
+
|
91 |
+
You should have received a copy of the GNU General Public License
|
92 |
+
along with this program; if not, write to the Free Software
|
93 |
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
94 |
+
|
95 |
+
|
96 |
+
|
97 |
+
== Installation ==
|
98 |
+
Please see our detailed [Installation Guide](http://businessdirectoryplugin.com/docs/#install), the [Quick Start Guide](http://businessdirectoryplugin.com/quick-start-guide/) for common how-to scenarios, and our [Initial Setup](http://businessdirectoryplugin.com/docs/#setup) page for instructions on how to get going quickly with Business Directory Plugin.
|
99 |
+
|
100 |
+
[Full documentation](http://businessdirectoryplugin.com/docs/) for the plugin is also available.
|
101 |
+
|
102 |
+
If you are having problems please visit [support forum](http://www.businessdirectoryplugin.com/support-forum/) for help.
|
103 |
+
|
104 |
+
|
105 |
+
== Screenshots ==
|
106 |
+
|
107 |
+
[Visit the main site for feature lists and screenshots](http://businessdirectoryplugin.com/features/)
|
108 |
+
|
109 |
+
|
110 |
+
== Changelog ==
|
111 |
+
= Version 3.5.4 =
|
112 |
+
* Improve "the_content" filter support.
|
113 |
+
* Add pagination support to the featured levels shortcode.
|
114 |
+
* Make category list responsive.
|
115 |
+
* Work around a WP bug related to importing categories with ampersands.
|
116 |
+
* Fix a JS conflict in some admin metaboxes.
|
117 |
+
* Add new "e-mail template" setting type.
|
118 |
+
* Added some new e-mail notifications.
|
119 |
+
* Prevent removal of listings with active recurring payments.
|
120 |
+
* Do not include custom fields on the CSV import page.
|
121 |
+
|
122 |
+
= Version 3.5.3 =
|
123 |
+
* Various changes related to EDD.
|
124 |
+
* Allow removal of listing ID from URLs.
|
125 |
+
* New e-mail template for expiration notices of auto-renewed listings.
|
126 |
+
* Add "Manage Subscriptions" page to review/cancel subscriptions.
|
127 |
+
* Fix permalink generation issues for unpublished listings.
|
128 |
+
* Fix preview support.
|
129 |
+
* Use the "do_shortcode" action instead of "the_content" filter for processing content fields.
|
130 |
+
* Make listing page dates match those from the listing being displayed.
|
131 |
+
* Add a default category on install.
|
132 |
+
* Add support for images to all widgets.
|
133 |
+
* Improve form fields CSS classes.
|
134 |
+
* Fix a couple of undefined variables warnings.
|
135 |
+
* Add ability to limit sending of contact messages.
|
136 |
+
* Allow re-ordering of fee plans.
|
137 |
+
* Display current version in admin panel.
|
138 |
+
* Re-schedule expiration hook if it is somehow disabled.
|
139 |
+
|
140 |
+
= Version 3.5.2 =
|
141 |
+
* Fix inexact searches for text fields.
|
142 |
+
* Strip slashes from search terms before performing the search.
|
143 |
+
* Fix display of search terms containing apostrophes.
|
144 |
+
* Add setting for notifying admins of listing edits.
|
145 |
+
* Do not send expiration notices for listing fees that auto-renew.
|
146 |
+
* Notify users via e-mail after auto-renewal of listing fees.
|
147 |
+
* Add support for Lightbox gallery mode.
|
148 |
+
* Add form to capture uninstall reasons.
|
149 |
+
* Listing cost now includes fees assigned using the backend.
|
150 |
+
* Support Yoast's OpenGraph tags.
|
151 |
+
* Minor WordPress API changes for 3.6 compatibility.
|
152 |
+
|
153 |
+
= Version 3.5.1 =
|
154 |
+
* Fix loading of custom CSS styles.
|
155 |
+
* Add random sorting to Featured Listings widget.
|
156 |
+
* Do not allow editing/deleting listings with no author from the front end.
|
157 |
+
* Fix a warning related to EDD.
|
158 |
+
* Minor fixes to the upgrade procedure.
|
159 |
+
|
160 |
+
= Version 3.5 =
|
161 |
+
* Various upgrade routine fixes
|
162 |
+
* Added more robust reCAPTCHA checks and anti SPAM measures for contact and comment forms.
|
163 |
+
* Improve registration URL behavior.
|
164 |
+
* Various minor CSV import/export fixes.
|
165 |
+
* Fix an issue that prevented listings from being displayed when sorting paid listings first
|
166 |
+
* Show empty categories by default.
|
167 |
+
* Added warning when empty categories is on and categories are empty
|
168 |
+
* Submit listing no longer ignores invalid reCAPTCHAs.
|
169 |
+
* Fix fatal error occurring when no title could be obtained for a listing.
|
170 |
+
* Include OpenGraph tags on listing pages for better FB sharing experiences.
|
171 |
+
* Search single valued fields in an exact manner for improved performance.
|
172 |
+
* Various quick search fixes.
|
173 |
+
* Display a warning when choosing too many text quick search fields.
|
174 |
+
* Display directory counts for users with editor permissions.
|
175 |
+
* Add support for updating listings via CSV imports.
|
176 |
+
* Various code quality fixes.
|
177 |
+
* Count listings in admin more efficiently.
|
178 |
+
* Allow listings with expired categories to be edited if they are published
|
179 |
+
* Make backend use frontend permalinks for previews.
|
180 |
+
* Workaround WP's bug #18857 that results in admin pages slugs being translated and resources not loading.
|
181 |
+
* Checked compatibility with WordPress 4.0.
|
182 |
+
* Various manual upgrade fixes.
|
183 |
+
* Integrate Easy Digital Downloads cart support for premium modules.
|
184 |
+
|
185 |
+
= Version 3.4.1 =
|
186 |
+
* Various upgrade routine fixes
|
187 |
+
* Respect default post statuses after CSV import
|
188 |
+
* Quick search fixes
|
189 |
+
* Better handle JWT class conflicts
|
190 |
+
* Fix typo to support old shortcodes
|
191 |
+
* Prefix some CSS classes to avoid theme conflicts
|
192 |
+
* Better support for MySQL’s STRICT mode
|
193 |
+
* Fix shortcode detection
|
194 |
+
* Various image upload fixes
|
195 |
+
* Added shortcode for advanced search page [businessdirectory-search]
|
196 |
+
|
197 |
+
= Version 3.4 =
|
198 |
+
* New [businessdirectory-featuredlistings] shortcode.
|
199 |
+
* New Payments API that supports recurring payments.
|
200 |
+
* New listing submit/edit process.
|
201 |
+
* Add OpenTags metadata for better Facebook sharing support
|
202 |
+
* New "sort bar" that allows users to sort listings on front end by various criteria configurable on back end.
|
203 |
+
* Add support for CC'ing notifications to an e-mail address other than the admin's.
|
204 |
+
* Do not allow change or category fees for frontend edits.
|
205 |
+
* Allow admins to override registration URL.
|
206 |
+
* Redirect users back to the page they were before registration.
|
207 |
+
* Fix PHP warnings during CSV exports.
|
208 |
+
* Workaround for static binding support in PHP < 5.3.
|
209 |
+
* Add rel="lightbox" to listing thumbnails.
|
210 |
+
* Add default arguments to _meta_title hook.
|
211 |
+
* Use get_temp_dir() to locate WP's temp directory.
|
212 |
+
* Alert admin when there is not a valid temp directory for CSV imports.
|
213 |
+
* Do not allow TIFF images to be uploaded.
|
214 |
+
* Check compatibility with WP 3.9.
|
215 |
+
* Streamline listing edit process.
|
216 |
+
* Correct typo affecting anonymous listing submits.
|
217 |
+
* Do not send notification emails when a listing is edited.
|
218 |
+
* Fix some CSV export file path problems.
|
219 |
+
* Add more robust error handling to the CSV export process.
|
220 |
+
* Prevent multiple listing submits.
|
221 |
+
* Fix compatibility with latest Yoast version.
|
222 |
+
* Load CSS and JS resources only on directory pages to improve site performance.
|
223 |
+
* Minify CSS and JS resources to improve response times.
|
224 |
+
* Support both [businessdirectory-manage_listings] and [businessdirectory-managelistings].
|
225 |
+
* Fix admin-side renewal of listings.
|
226 |
+
* Remove PHP session usage from BD.
|
227 |
+
* Fix anonymous users not being able to upload images in Image fields.
|
228 |
+
* Add new update/migration routine.
|
229 |
+
* Add a 'Settings' link on Plugins page.
|
230 |
+
* Contact messages template can now be changed via "Manage Options".
|
231 |
+
* Fix support for tag fields of checkbox type.
|
232 |
+
* Improve listings shortcode display when multiple categories are used.
|
233 |
+
* Fix a bug where uninstall would not remove all tables and data.
|
234 |
+
* Add password recovery link to login template.
|
235 |
+
* Quick searches can now be performed in all fields. Other search improvements.
|
236 |
+
* Several admin-side UI improvements.
|
237 |
+
* Add a dedicated e-mail settings tab.
|
238 |
+
* Improve compatibility with PHP 5.2.
|
239 |
+
* Fix an error when saving multivalued form fields.
|
240 |
+
* Work around for Google Analytics plugin rewriting javascript-callback links.
|
241 |
+
* Consolidate all e-mail template settings in one place.
|
242 |
+
* Correctly apply default post status after listing submits.
|
243 |
+
* Form fields can now be sorted via drag and drop.
|
244 |
+
* Integrate all gateways with 3.4 submit process.
|
245 |
+
* Integrate all gateways with new Payments API.
|
246 |
+
* Improve "Manage Restrictions" screen usability.
|
247 |
+
* Integrate with the new 3.4 submit process.
|
248 |
+
* Make character restrictions ignore new lines.
|
249 |
+
* Fix truncation of text when character restrictions are in place.
|
250 |
+
* Allow module to restrict "reply to" listing functionality.
|
251 |
+
* Make sure themes or plugins don't override Google Maps JS sensor argument.
|
252 |
+
* Replace cURL function calls with wp_remote_get calls.
|
253 |
+
* Show admins a warning when listings have not been geocoded due to Google API limits.
|
254 |
+
* Play nice with other themes/plugins to avoid including the Google Maps JS API multiple times.
|
255 |
+
* Add support for subscriptions (recurring payments).
|
256 |
+
* Fix incorrect search query being generated when ratings field was not visible.
|
257 |
+
* Fix typo in Ratings that caused AJAX edits to fail.
|
258 |
+
* Add email notification for ratings pending approval.
|
259 |
+
* Allow users to choose where the rating field appears.
|
260 |
+
* Stripe gateway initial release.
|
261 |
+
* Add Mexico postal code database support.
|
262 |
+
* Updated US database.
|
263 |
+
* Fix typo in search algorithm.
|
264 |
+
* Fix cache expiration detection code.
|
265 |
+
* Integrate with 3.4 submit process.
|
266 |
+
* Index some MySQL columns for improved performance.
|
267 |
+
* Allow admins to configure how radius search works.
|
268 |
+
* Fix detection of incompatible gateways being enabled at the same time as PayFast.
|
269 |
+
|
270 |
+
= Version 3.3 =
|
271 |
+
* Minor changes for WP 3.8 compatibility (admin CSS).
|
272 |
+
* Show fee selection screen when offer upgrades on submit is active so listings can be upgraded even when no fees are configured.
|
273 |
+
* Display category ID on the Directory Categories table.
|
274 |
+
* CSV export now works in batches to avoid timeout and memory limits.
|
275 |
+
* Fix escaping issue in settings API.
|
276 |
+
* Fix incorrect category counts.
|
277 |
+
* Allow multiple categories when using the category shortcode.
|
278 |
+
* Fix reCAPTCHA conflicts with regular post comments.
|
279 |
+
* Add a separate setting for listings per page.
|
280 |
+
* Allow for empty selection of select fields in searches.
|
281 |
+
* Allow changing expiration dates of listing fees in the admin.
|
282 |
+
* Change int columns to bigint for scalability reasons.
|
283 |
+
|
284 |
+
= Version 3.2.2 =
|
285 |
+
* Patch for categories problem introduced by renaming in 3.2.1
|
286 |
+
|
287 |
+
= Version 3.2.1 =
|
288 |
+
* Migrate Google Checkout to Google Wallet, updated gateways, workflow, API
|
289 |
+
|
290 |
+
= Version 3.2 =
|
291 |
+
* Add option to track BD setups for testing purposes.
|
292 |
+
* Correctly import URLs through CSV files.
|
293 |
+
* Make the entire top button bar hidden if no button is displayed.
|
294 |
+
* Apply a more efficient query to count expired listings in admin as not to block the site.
|
295 |
+
* Display expired categories just one time inside the category column admin-side.
|
296 |
+
* Make listing sort options uniform.
|
297 |
+
* Added random sort option for listings.
|
298 |
+
* Added option to display listing thumbnails in the Featured Listings widget.
|
299 |
+
* Change default to not trash expired listings.
|
300 |
+
* Added support for Terms & Conditions to be required at submit time.
|
301 |
+
* Added CSV export tool that exports listing info including featured status & expiration info.
|
302 |
+
* Added support for featured status & listing expiration date columns for CSV imports.
|
303 |
+
* Fully respect listing image display settings.
|
304 |
+
* Update bundled reCAPTCHA library to latest version.
|
305 |
+
* Do not import reCAPTCHA library when reCAPTCHA functions are already available.
|
306 |
+
* Add reCAPTCHA support to the listing comment form.
|
307 |
+
* Add official spanish (es_ES) translation.
|
308 |
+
* Fixed typos in strings
|
309 |
+
* Allow admins to decide how listing owners are to be contacted.
|
310 |
+
* Added ability for reminder email on renewals past due.
|
311 |
+
* Added ability to allow HTML input in TextArea fields.
|
312 |
+
* Make category field respect "hide empty categories" in search widget.
|
313 |
+
* Workaround for Simple Facebook Connect conflicts.
|
314 |
+
* Added notice on Registration tab when Registration is off on the site and listing submit requires login.
|
315 |
+
* Added special CSS class to subcategories in main category list.
|
316 |
+
* Fixed for category counts being incorrect in some special scenarios.
|
317 |
+
* Fixed payment gateway availability check in Directory - Main Menu page.
|
318 |
+
* Avoid recursion errors during wpbdp_get_page_link calls.
|
319 |
+
* Allow HTML in field label & description.
|
320 |
+
* Fixed expiration notification code that prevented emails from being sent in some cases.
|
321 |
+
* Workaround a WordPress bug that causes terms with ampersands to be missed in searches.
|
322 |
+
* Add option that allows execution of WP filters/shortcodes inside content fields.
|
323 |
+
* Fixed a bug where the author was being reverted to admin when editing a listing.
|
324 |
+
* Updated category walker code to match WP's 3.6.1.
|
325 |
+
* Improved SEO capabilities and Yoast SEO integration.
|
326 |
+
* Fixed an incorrect SQL query run when deleting form fields.
|
327 |
+
|
328 |
+
= Version 3.1.1 =
|
329 |
+
* Fixed add listing shortcode issue
|
330 |
+
* Fixed featured levels field association save problem
|
331 |
+
* Changed workflow to not display fee step when nothing is payable
|
332 |
+
* Fixed Edit button problem (where it showed the Add Listing screen instead of edit)
|
333 |
+
* Fixed search results to use the blog setting instead of 10 listings
|
334 |
+
* Fixed CSV import issue
|
335 |
+
|
336 |
+
= Version 3.1 =
|
337 |
+
* New module: Featured Levels
|
338 |
+
* New module: Category Icons
|
339 |
+
* New module: ZIP code search
|
340 |
+
* Allow search form to be hidden when results are displayed.
|
341 |
+
* Fix handling of NULL/empty column values in some MySQL databases that confused the Form Fields API.
|
342 |
+
* Do not fail when a listing's 'sticky' flag appears twice (or more) in the database .
|
343 |
+
* Honor edit-post status after a listing edit .
|
344 |
+
* Make WordPress generate valid permalinks for a recently submitted listing
|
345 |
+
* Use update_post() instead of publish_post() to force WP not to trash existing permalink slugs when bulk-publishing listings
|
346 |
+
* Do not print empty subcategory lists in the main category view.
|
347 |
+
* If options are manually specified in a tag field use them as choices instead of the whole tag taxonomy list.
|
348 |
+
* Add a workaround for a known PHP issue where empty and zero values are incorrectly compared.
|
349 |
+
* Improve title handling compatibility with Yoast SEO plugin.
|
350 |
+
* Reviewed compatibility with PHP 5.3 & WP 3.5.2.
|
351 |
+
* Make uninstall process actually delete all settings and BD content.
|
352 |
+
* Do not display the upgrade to featured option when submitting a listing if featured listings are disabled.
|
353 |
+
* Fix numbering of submit process steps.
|
354 |
+
* Make category fields respect configured category ordering when they are rendered.
|
355 |
+
* Categories are now displayed hierarchically when using checkbox/radio category fields.
|
356 |
+
* Fix unpaid listing count in admin.
|
357 |
+
* Do not change the listing status back to pending if it was already published when a transaction is approved.
|
358 |
+
* Extend Yoast SEO support to include category & tag descriptions.
|
359 |
+
* Payment process page now displays error messages that come from the payment gateway.
|
360 |
+
* Allow plugin to work correctly when its directory is a symlink.
|
361 |
+
* Workaround Relevanssi plugin causing problems uploading images.
|
362 |
+
* Correctly escape & unescape strings when saving and displaying a field's name.
|
363 |
+
* Restore 'preview' functionality for listings admin-side.
|
364 |
+
* Use category/tag description for category/tag pages metatags.
|
365 |
+
* Compatibility with XML site maps reviewed.
|
366 |
+
* Fix handling of comma/semicolon-separated tags in CSV import.
|
367 |
+
* Make category fields work correctly when using radio buttons.
|
368 |
+
* Add a pending expiration/renew ad email that is sent a configurable number of days before the actual listing expiration happens
|
369 |
+
* Listings get republished after a renewal.
|
370 |
+
* New core filters/actions to allow plugins to display and handle field settings in the admin.
|
371 |
+
* Improve handling of expired categories in listings admin-side.
|
372 |
+
* Allow users to opt-out of a listing renewal.
|
373 |
+
* Add a new 'expired' filter to quickly find listings with expired categories.
|
374 |
+
* New "Transactions" section to administrate listing transactions.
|
375 |
+
* Use a better return/cancel URL for the PayPal module .
|
376 |
+
* Fix SQL query that returned incorrect results when filtering listings by rating in Advance Search.
|
377 |
+
* Allow ratings tooltips to be overridden by the user.
|
378 |
+
* Change default start tooltips to more sane default values.
|
379 |
+
* Geolocate listings server-side instead of using the JS API to avoid hitting Google Maps limits.
|
380 |
+
* Performance enhancements.
|
381 |
+
* Show all relevant listings in a category or search results page instead of just the ones visible on the page.
|
382 |
+
* Use newlines instead of commas to separate address parts when displaying a map pin.
|
383 |
+
* Use a special hash to mark listings that need to be geolocated to avoid unnecessary hits to the Maps API.
|
384 |
+
* Do not fail when an expected region form field was manually deleted by the admin
|
385 |
+
* Workaround WordPress showing incorrect listing counts for the Regions taxonomy.
|
386 |
+
* Make Regions cache regeneration work even if some region fields are not present.
|
387 |
+
* Fix display of incorrect regions in the sidelist when no region field was visible.
|
388 |
+
* Allow region selector to be completely hidden.
|
389 |
+
* Show an admin warning when regions is incorrectly configured
|
390 |
+
* Allow listings to be assigned a region admin-side even before the first save.
|
391 |
+
* Reset current page variable when changing the current region.
|
392 |
+
* Move all settings to "Manage Options" section.
|
393 |
+
* Add a display flag specific for the region selector.
|
394 |
+
* Fix region fields display so that the order in which the fields appear doesn't affect functionality.
|
395 |
+
* New location search widget (ZIP code module).
|
396 |
+
* Added support for US/UK and US+UK postal code databases in ZIP module.
|
397 |
+
|
398 |
+
|
399 |
+
= Version 3.0.2 =
|
400 |
+
* Further additions to allow for restoration of "invalid" fields for 3.0 users affected by 2.2->3.0 upgrade
|
401 |
+
|
402 |
+
|
403 |
+
= Version 3.0.1 =
|
404 |
+
* Added code to workaround critical WordPress dbDelta issue with PHP 5.2.x users
|
405 |
+
* Fixed category display bug where "Hide Empty Categories" would hide all categories instread.
|
406 |
+
|
407 |
+
|
408 |
+
= Version 3.0 =
|
409 |
+
* New form fields API
|
410 |
+
* Allow for label hiding in form fields
|
411 |
+
* New URL field
|
412 |
+
* URL Validator now supports more schemes other than http or https
|
413 |
+
* Social fields marked as "optional" do no longer fail to validate when empty
|
414 |
+
* Make social fields work correctly with URL Validator
|
415 |
+
* Fix an issue with single checkbox fields
|
416 |
+
* Now possible to specify if a URL field has rel="nofollow" or not
|
417 |
+
* Fix a re-ordering issue with bottom most fields
|
418 |
+
* Fix an issue with radio button fields showing labels twice
|
419 |
+
* Restore ability to hide the search form
|
420 |
+
* Simplify WordPress queries to improve loading speed for directory pages
|
421 |
+
* Search results are now sorted using the directory configured setting
|
422 |
+
* Added option to notify admins via email when new listings are posted
|
423 |
+
* Allow listings to be upgraded to featured during the initial submit process, This option is controlled by the "Offer upgrades during submit process?" setting.
|
424 |
+
* Include listings in children categories in search results when searching a category
|
425 |
+
* Make tag association work correctly with checkboxes
|
426 |
+
* All BD buttons have now class 'button' or 'submit' depending on their type for easier theming
|
427 |
+
* Form elements in widgets, search form, etc. now use specific IDs for easier theming
|
428 |
+
* Handle accented words and apostrophes correctly when importing listings via CSV files.
|
429 |
+
* Allow users with edit permissions to change listing images in backend
|
430 |
+
* Fix category posts being incorrectly counted when there were expired listings
|
431 |
+
* CSV import now complaints when a required field column is not present
|
432 |
+
* CSV import now complaints when a user isn't found
|
433 |
+
* Do not change listing author when using quick edit in the admin
|
434 |
+
* Plugin checked for WPMU compatibility
|
435 |
+
* Preserve the language parameter in BD links when qTranslate plugin is found to be active
|
436 |
+
* Fix image issue due to conflicts with Jetpack plugin
|
437 |
+
* Add "Listings Tagged: [tag]" to the title & header of tag pages
|
438 |
+
* Fix an issue where paid listings were being published even when the payment was skipped
|
439 |
+
* Add Lightbox support
|
440 |
+
* Admin menus minor reorganization
|
441 |
+
* Add a "Clear" button to the search form
|
442 |
+
* Make use of listing emails before others for delivering renewal emails
|
443 |
+
* Detect some conflicting social plugins (AddThis Social Bookmarking Widget, Jamie Social Icons, TF Social Share, Shareaholic, Quick AdSense) and disable them on directory pages
|
444 |
+
* Call 'handle_action' further down the action pipeline to avoid problems with other plugins
|
445 |
+
* Rewrite rules and query vars cleanup
|
446 |
+
* Fix canonical redirects so the BD page works even when set as home page
|
447 |
+
* Lots of deprecated functions removed and code cleanups.
|
448 |
+
* Better detection of the current action being performed inside BD pages
|
449 |
+
* Do not overwrite titles of pages outside of BD. Fixes a conflict with AWPCP
|
450 |
+
* Produce correct 'canonical' link head tags for listings, categories and tag pages
|
451 |
+
* Make BD support Yoast SEO plugin's metadata and title tags on listing pages.
|
452 |
+
* Include RSS feed links for listings and categories in directory pages
|
453 |
+
|
454 |
+
|
455 |
+
= Version 2.2 =
|
456 |
+
* Added support for Regions module
|
457 |
+
* Fixed CSV import error for PHP character munging
|
458 |
+
|
459 |
+
|
460 |
+
= Version 2.1.6.1 =
|
461 |
+
* Fix PHP 5.4 error during install
|
462 |
+
* Fix error "Fee must be associated to a category" when a category was selected.
|
463 |
+
|
464 |
+
|
465 |
+
= Version 2.1.6 =
|
466 |
+
* Support for all currencies supported by PayPal.
|
467 |
+
* Do not make URL fields required when marked as optional.
|
468 |
+
* When searching a field with multiple options, the options are now ORed.
|
469 |
+
* Twitter field type for @ handles. On display, a "Follow" button appears.
|
470 |
+
* Facebook field type for pages. On display, a "Like" button appears.
|
471 |
+
* LinkedIn field type for company IDs (not supported for individual profiles). On display, a "Follow" button appears.
|
472 |
+
* Image settings in "Manage Options" are always respected (no approximate sizes are used). Thumbnails of the correct size are automatically created when an image is uploaded.
|
473 |
+
* If image settings change, new thumbnails are created on the fly when a listing is visited. This happens only on "single view" to avoid consuming a lot of server resources.
|
474 |
+
* When uploading images at the submit/edit listing form useful errors are now displayed. This happens when images are of a bigger size than allowed or are not really image files. Previously, it wasn't clear why an upload could fail.
|
475 |
+
* Long description can now be set to Optional, required fields that can't be changed have disabled checkbox shown
|
476 |
+
* Empty URL field labels are not displayed
|
477 |
+
* CSV importer fixes for descriptions with newlines
|
478 |
+
* Fixed PO file to include Directory button label
|
479 |
+
* Hide payment & fee info on posts from non-administrators
|
480 |
+
* Upgrade PayPal interface for compatibility alert due in Feb 2013 (HTTP headers)
|
481 |
+
|
482 |
+
|
483 |
+
= Version 2.1.5.2 =
|
484 |
+
* Added support for PayPal currencies: BRL, TRY, MRY
|
485 |
+
* Fixed bug where upgrade of Website address did not auto-copy the link text
|
486 |
+
* Fixed advanced search issues with categories
|
487 |
+
* Fixed advanced search to use OR instead of AND for multi-select listboxes
|
488 |
+
* Fixed URL validator to not make field required when URL is empty
|
489 |
+
* Fixed permalink rules to work with index.php-based approach
|
490 |
+
|
491 |
+
|
492 |
+
= Version 2.1.5.1 =
|
493 |
+
* Fixed WP API change: Missing argument 2 for wp_kses()
|
494 |
+
|
495 |
+
|
496 |
+
= Version 2.1.5 =
|
497 |
+
* Added a Back to Directory button for listings
|
498 |
+
* Added sorting order for ratings (by ratings and count)
|
499 |
+
* Minor HTML tweaks for layout
|
500 |
+
* Added Link Text for Business Website (to create a complete anchor tag with SEO value)
|
501 |
+
* Changed fields to be hideable from Advanced Search Form
|
502 |
+
* Added better error messages displayed when payment gateways are not correctly configured for use
|
503 |
+
* Added payment skipping for admins, including a message that clearly shows the payments are being skipped because the current user is an admin
|
504 |
+
* Comments in listings are correctly displayed now
|
505 |
+
* CSV import now supports newlines in the import fields
|
506 |
+
* Contributors can't manage listings now
|
507 |
+
* Removed HTML comments from core templates that caused problems with some themes
|
508 |
+
* Category and tag names are now displayed in the page title
|
509 |
+
* Fixed Google Checkout Seller ID issue (removed field)
|
510 |
+
* Fixed labels for directory so that the colon is not outside the label
|
511 |
+
* rel attribute added to images
|
512 |
+
* Search widget added
|
513 |
+
* CSV import now supports multiple categories using the category separator
|
514 |
+
* Fixed stripslashes bug with field labels
|
515 |
+
|
516 |
+
|
517 |
+
= Version 2.1.4.1 =
|
518 |
+
* Fixed issue with default display of form fields (caused fields to hide in listing)
|
519 |
+
|
520 |
+
|
521 |
+
= Version 2.1.4 =
|
522 |
+
* Added support for Ratings module
|
523 |
+
* Fixed problems with comments
|
524 |
+
* Fixed problem with featured listings not displaying on the page with the correct count
|
525 |
+
* Improved speed of queries for main listings
|
526 |
+
* Fixed search pagination issue with lengthy result sets
|
527 |
+
* Fixed issue where number of posts per page did not include featured listings
|
528 |
+
|
529 |
+
|
530 |
+
= Version 2.1.3 =
|
531 |
+
* Fixed shortcode usage problems with new codes
|
532 |
+
* Fixed permalink issues with categories and listings
|
533 |
+
* Added the Directory button back to most pages for simpler navigation.
|
534 |
+
* Added the ability to hide the directory button in the admin options
|
535 |
+
* Fixed HTML template issues for listings and single view pages (buttons showed HTML as text)
|
536 |
+
* Added error message when the main shortcode is not present on any page
|
537 |
+
* Fixed 2Checkout plugin for 2.1.2
|
538 |
+
* Fixed search page pagination
|
539 |
+
* Added back pagination API from WordPress for listings page, fixed bugs where post display was not honored
|
540 |
+
* Added checks for tags and slugs using permalink rules
|
541 |
+
* Fixed submit listing to only submit listing once when clicked repeatedly (or refreshed by accident)
|
542 |
+
* Added reCAPTCHA support to comments AND listings both
|
543 |
+
* Fixed CSV import issues with permalinks and dates
|
544 |
+
* Fixed payment gateway deactivation issues when plugin is upgraded.
|
545 |
+
* Improved search query speeds
|
546 |
+
* Added ability to select whether a field should appear on the listing's single view and/or excerpt view separately.
|
547 |
+
* Admins can edit / upgrade listings through the frontend regardless of the listing payment status.
|
548 |
+
* A confirmation dialog is now shown when deleting a listing.
|
549 |
+
* Comments on listings always follow the setting inside "Manage Options" (don't have to enable/disable comments individually on listings through the admin side).
|
550 |
+
* Fixed issue with custom CSS: files can be placed inside the "wp-plugin" directory now (per the docs).
|
551 |
+
|
552 |
+
|
553 |
+
= Version 2.1.2 =
|
554 |
+
* Fixed critical query issue that prevented short code pages from working (Add Listing/Edit Listing)
|
555 |
+
|
556 |
+
|
557 |
+
= Version 2.1.1 =
|
558 |
+
* Fixed Directory button to display in listings
|
559 |
+
* Minor CSS tweaks to show labels in bold
|
560 |
+
* Fixed bug with category and single listing links where they would not display when clicked (404 error)
|
561 |
+
|
562 |
+
|
563 |
+
= Version 2.1 =
|
564 |
+
* Added support for CSV import, including images in ads
|
565 |
+
* Added support for custom CSS extensions via CSS files outside of BD
|
566 |
+
* Added new shortcode names (easier to remember). Old shortcodes still supported.
|
567 |
+
* Added support for parameters on WPBUSDIRMANMVIEWLISTINGS/businessdirectory-viewlistings to allow for single category display on a page.
|
568 |
+
* Upgraded search to have "Advanced Search" link now, all fields are searchable.
|
569 |
+
* Streamlined the submit process for Free ads (no longer asks for payment)
|
570 |
+
* Website URL opens in new window (new field option for URLValidated fields)
|
571 |
+
* New widgets: Featured Listings, Latest Listings, Random Listings
|
572 |
+
* HTML emails: Email sent in HTML format instead of text now
|
573 |
+
* Preview Form is back.
|
574 |
+
* Google Maps now recognized on Premium Modules panel as installed/not installed
|
575 |
+
* MASSIVE upgrade to theming/theme integration, much easier to get BD going now. Still have override templates, but fewer than before.
|
576 |
+
* Page based navigation--allows for tighter theme integration and easier upgrades. Requires the use of permalinks for pretty URLs
|
577 |
+
* Fixed problem with URL validator not working right.
|
578 |
+
* Fixed problem with IE9 and button display
|
579 |
+
* Fixed ad pagination problem.
|
580 |
+
* Fixed problem with ad expiration validation (where 9999 caused weird 404 errors)
|
581 |
+
* Category list call from API now working again.
|
582 |
+
* Subcategory display problem in admin panel fixed.
|
583 |
+
* Users must select a category when creating a fee plan
|
584 |
+
* Fixed bug with Manage Form Fields button on Main Menu (permission issue)
|
585 |
+
|
586 |
+
|
587 |
+
= Version 2.0.5 =
|
588 |
+
* Added ability to use bulk operations from admin menu (Upgrade/Downgrade, Set Paid, etc)
|
589 |
+
* Fixed problem with PayPal module not redirecting after payment on some sites
|
590 |
+
* Removed BD metadata from deleted posts (speeds searches)
|
591 |
+
* Fixed wp_pagenavi() warning
|
592 |
+
* Fixed bug where website field could not be cleared of data
|
593 |
+
* Fixed issue where admin could not edit other listings
|
594 |
+
* Added confirmation email to be sent after listing is complete
|
595 |
+
* Changed Upgrade to only work for Admins
|
596 |
+
* Updated plugin to use wpdb->query for all DB operations
|
597 |
+
* Fixed pagination problem with "Older listings" link
|
598 |
+
* Fixed duplicate search issue (duplicate results returned on searches)
|
599 |
+
* Fixed sticky/featured listing sorting problem to be consistent for category, listing and page views
|
600 |
+
|
601 |
+
|
602 |
+
= Version 2.0.4.1 =
|
603 |
+
* Fixed image upgrade issues (missing thumbnails, duplicate pictures in listings)
|
604 |
+
* Fixed edit glitch with empty tags field
|
605 |
+
* Added control over Submit a Listing button to show/hide. Added support for other listing buttons as well.
|
606 |
+
* Fixed minor _x() calls with missing parameters
|
607 |
+
* Fixed an issue with submitting listings for all blank fields (PHP warning)
|
608 |
+
* Fixed issue where empty fields would display labels when no value was present
|
609 |
+
|
610 |
+
= Version 2.0.4 =
|
611 |
+
* Upgrade to image upload/management system
|
612 |
+
* Fixed form for creating new listings, both admin and user side
|
613 |
+
* Fixed listing renewal, emails now go out prior to expiration
|
614 |
+
* Payment modules upgraded to handle renewals
|
615 |
+
* POST variables now properly configured for Windows and Linux
|
616 |
+
* div's properly closed on Submit Listing
|
617 |
+
* Comments will display when option is checked now
|
618 |
+
* Directory definition issue with wp-content fixed
|
619 |
+
* Require registration option now properly displays in admin panel
|
620 |
+
* Field metadata is hidden and properly namespaced
|
621 |
+
* Sticky listings in category no longer cause No Listings Found
|
622 |
+
* Translation issue fixed
|
623 |
+
* Location field will not disappear on upgrade
|
624 |
+
* Invalid argument foreach() issue fixed
|
625 |
+
* Email now goes to site owner as expected
|
626 |
+
* Submit Listing layout problems fixed
|
627 |
+
* Submit listing duplicate fields display fixed
|
628 |
+
* Manage fees upgraded for renewals
|
629 |
+
* Image displays in list and single view properly now
|
630 |
+
* Editing listings will not randomly change category now
|
631 |
+
* Users can control which image is set for the thumbnail of a listing now
|
632 |
+
* Support for multiple categories in a listing added
|
633 |
+
* Add New Listing navigation bug fixed
|
634 |
+
|
635 |
+
= Version 2.0.3 =
|
636 |
+
* Autocreate required fields
|
637 |
+
* Directory admin menu set to be visible only to administrator role
|
638 |
+
* Content field will not show as link now
|
639 |
+
* Reply emails go to the business listing instead of site owner
|
640 |
+
* Listings without photos now no longer have placeholder
|
641 |
+
* Submit Listing no longer displays raw HTML code to user
|
642 |
+
* Plugin now uses UTF-8 functions to properly handle non-ASCII characters
|
643 |
+
* BD now integrates in a more friendly way with themes, avoids overriding when possible
|
644 |
+
* preg_match() warning fixed
|
645 |
+
* Extra line breaks removed from listing display
|
646 |
+
* Conflict with Yoast All in One SEO fixed
|
647 |
+
* Changing the slug now checks for reserved/already used slugs to avoid conflict
|
648 |
+
* Form fields now custom ordered
|
649 |
+
* Module detection code fixed, now displays which modules are installed for PayPal/2Checkout
|
650 |
+
|
651 |
+
|
652 |
+
= Version 2.0.2 =
|
653 |
+
* A revamped form-fields system that would allow plugins to create or use their own custom fields and validation rules.
|
654 |
+
* A new "Manage Form Fields" page which looks better and conveys information in a more friendly way.
|
655 |
+
* Custom fields can now be ordered as the user wishes. This ordering is used when displaying both the add/edit forms and listing information.
|
656 |
+
* Allow users to specify if a particular field should be displayed in excerpt or not at all.
|
657 |
+
* A better add/edit form-field page including some AJAX tricks to hide unnecessary fields. For instance, when you select a "Textfield" the "Options" field is hidden because the field isn't multivalued. The form is now also a standard WP form.
|
658 |
+
* A new "field description" field that could be used by admins to display additional information along the form fields.
|
659 |
+
* Validation when adding/editing custom form-fields to prevent users from removing or modifying required fields (like title, content, etc.)
|
660 |
+
* New validation framework for fields.
|
661 |
+
* Fixed bug where Featured ads could not be downgraded.
|
662 |
+
* Fixed delete field bug.
|
663 |
+
* Fixed ereg() warning bug.
|
664 |
+
|
665 |
+
|
666 |
+
= Version 2.0.1 =
|
667 |
+
* Fixed scripting error with booleans for some WP installs
|
668 |
+
* Fixed category 404 problems, clean up navigation
|
669 |
+
* Fixed short description display issue
|
670 |
+
* Fixed shortcode usage problems (content displayed below directory, no matter where shortcode was)
|
671 |
+
|
672 |
+
|
673 |
+
= Version 2.0 =
|
674 |
+
* Reset versioning to sensible convention
|
675 |
+
* Fixed search CSS and searching functionality
|
676 |
+
* Changed category management to simplify
|
677 |
+
* Added payment status, featured status into listing screen directly
|
678 |
+
* Google Checkout bug fix
|
679 |
+
* Fixed various scripting errors (22 bug fixes total)
|
680 |
+
* Button alignment fixes and admin UI cleanup
|
681 |
+
|
682 |
+
|
683 |
+
|
684 |
+
= Version 1.0 (1.9.6) =
|
685 |
+
Business Directory Plugin carries over from the last version of WP Business Directory Manager (1.9.5) Fixes include:
|
686 |
+
|
687 |
+
1. Sticky listings bug fix
|
688 |
+
|
689 |
+
2. Fixed broken submit form (raw html code displaying on front end)
|
690 |
+
|
691 |
+
3. Tags fixed (previously clicking on tag links did not display any tag related content)
|
692 |
+
|
693 |
+
4. New classes added for sticky listing styling
|
694 |
+
|
695 |
+
5. Addition of basic search feature
|
696 |
+
|
697 |
+
|
698 |
+
Previous changelog from WP Business Directory Manager
|
699 |
+
|
700 |
+
Version 1.9.3 - Sticky listings fix for error where upgraded listings were not being listed under "Manage Featured".
|
701 |
+
|
702 |
+
Paid listings fix for error where paid listings were not being listed under "Manage Payments"
|
703 |
+
|
704 |
+
Applied fix for payment calculation and handling where users are allowed to submit listing to multiple categories
|
705 |
+
|
706 |
+
Fixed bug with images where number of images left wass sometimes greater than the total number of images allowed
|
707 |
+
|
708 |
+
[ Thanks to Mike Bronner for his help with the below list of improvements and fixes to the plugin]
|
709 |
+
|
710 |
+
- Fixed issue where shortcodes would always cause the Add Listing Form to display prior to content.
|
711 |
+
|
712 |
+
- XHTML compliant.
|
713 |
+
|
714 |
+
- More versatile arrangement of form elements.
|
715 |
+
|
716 |
+
- Improved label handling (added proper IDs and FOR attributes).
|
717 |
+
|
718 |
+
- Changed 'wp_dropdown_categories' function call to pass in an array of arguments, and adding arguments "echo" and "class".
|
719 |
+
|
720 |
+
- Added functionality so that required fields receive a class name 'required'. This will allow for highlighting of required fields, etc.
|
721 |
+
|
722 |
+
- Added "required" class to input fields in AddListing form, allowing them to be stylized.
|
723 |
+
|
724 |
+
- Internal code optimization and cleanup.
|
725 |
+
|
726 |
+
- Added hooks (filters) on functions that display HTML to allow user overrides of those functions in functions.php in their template. This is possible by removing the filters, then re-adding them and pointing to their own functions using the functions.php file in their theme.
|
727 |
+
|
728 |
+
- "Add Listing" form will now submit back to itself. This will allow you to retain styling of the form separate from the directory. It is also no longer necessary for the Add Listing page to be a child of the Directory page.
|
729 |
+
|
730 |
+
- Expanded slightly on the hookability of the add listing functionality, further allowing other developers to extend the plugin.
|
731 |
+
|
732 |
+
- Updated text to be displayed on add listing form is user wasn't logged in.
|
733 |
+
|
734 |
+
|
735 |
+
Bug Fixes:
|
736 |
+
|
737 |
+
========
|
738 |
+
|
739 |
+
- Addressed issue where shortcodes would always be displayed above content. Now you can nest shortcodes between content.
|
740 |
+
|
741 |
+
- Updated HTML code to be XHTML complient
|
742 |
+
|
743 |
+
- Wrapped notifications in <p> tags, where not already done so.
|
744 |
+
|
745 |
+
- Wrapped free-standing text in token function, where not already done so (__("text", "WPBDM")).
|
746 |
+
|
747 |
+
- Fixed heading "Step 2" on image upload form to be H2 tag instead of H3 tag (syntactically correct, as there is otherwise no H2 tag).
|
748 |
+
|
749 |
+
|
750 |
+
|
751 |
+
Version 1.9.2 - Attempts to fix "undefined function flush_rewrite_rules" issue
|
752 |
+
Fixes "Wrong datatype for second argument" error when using checkbox field type for category field
|
753 |
+
Fixes default picture bug ( default picture not displaying )
|
754 |
+
|
755 |
+
|
756 |
+
Version 1.9.1 - Fixes a bug that defaults all extra fields to a type of text box regardless what the administrator selects. This bug was only present in version 1.9.0.
|
757 |
+
|
758 |
+
Version 1.9.0 - This version attempts yet again to fix the issue with categories showing "No Listings found in category" even while there are actually listings in the category.
|
759 |
+
Also attempts to fix situation where listings show up across all categories.
|
760 |
+
Adds the ability to post listings to multiple categories. To use this you must set the category associated field as a checkbox type.
|
761 |
+
Attempts to fix problem where when editing a listing if you had not uploaded any pictures the first time around it does not load the upload form on edit but says you don't have the ability to upload images
|
762 |
+
Attempts to fix the issue with the View button not taking you to the actual listing in Internet Explorer browser
|
763 |
+
Fixes a problem in the fields manager where if you saved a field without a label you then cannot delete the field.
|
764 |
+
Fixes URL validation bug
|
765 |
+
|
766 |
+
|
767 |
+
Version 1.8.9 - This version has a small fix for the Google checkout page and a fix for some permalink issues causing a variety of problems with pages. Regarding the google checkout it seems some previous versions were displaying the shortcode at all times and not showing the actual page content. Change made: The line
|
768 |
+
|
769 |
+
add_shortcode('WPBUSDIRMANGOOGLECHECKOUT', 'wpbusdirman_do_googlecheckout');
|
770 |
+
|
771 |
+
was changed to
|
772 |
+
|
773 |
+
if($wpbusdirman_hasgooglecheckoutmodule == 1)
|
774 |
+
{
|
775 |
+
add_shortcode('WPBUSDIRMANGOOGLECHECKOUT', 'wpbusdirman_do_googlecheckout');
|
776 |
+
}
|
777 |
+
|
778 |
+
and moved to below
|
779 |
+
|
780 |
+
if($wpbusdirman_hastwocheckoutmodule == 1)
|
781 |
+
{
|
782 |
+
add_shortcode('WPBUSDIRMANTWOCHECKOUT', 'wpbusdirman_do_twocheckout');
|
783 |
+
}
|
784 |
+
|
785 |
+
The update also adds 3 new options under a new setting "Permalink Options" that allows you to change the wpbdm-directory slug, the wpbdm-category slug and the wpbdm-tags slug. Please take note of the fact that you cannot use "category" or "tags" or any already reserved WordPress taxonomy names for your slugs as it will make your pages fail to load.
|
786 |
+
|
787 |
+
|
788 |
+
Version 1.8.8 - This version has a small fix in a function related to the payment process on sites that have only one fee setting applied to all categories.
|
789 |
+
|
790 |
+
Version 1.8.7 - This version attempts to fix the issues with the contact form not sending the email to the business but instead sending it to the user who was logged in when the listing was submitted.
|
791 |
+
|
792 |
+
This version attempts to fix the issues with some top level categories showing no listings found.
|
793 |
+
|
794 |
+
This version fixes the issue with the extra thumbnails not showing up in the listing
|
795 |
+
|
796 |
+
This version should fix the issue with the cannot redeclare username_exists() error
|
797 |
+
|
798 |
+
|
799 |
+
|
800 |
+
|
801 |
+
Version 1.8.6 - Removes call to include the WordPress registration.php in order to fix "Fatal error: Cannot redeclare username_exists() (previously declared in..." error
|
802 |
+
|
803 |
+
Version 1.8.5 - Fixes a bug that prevented the payment step from kicking in (applies for version 1.8 and above only)
|
804 |
+
|
805 |
+
Version 1.8.4 - Removes automatic creation of pages at setup to correct bug that caused multiple instances of the business directory page and sub pages to be created.
|
806 |
+
` Installation process now includes manual creation of the necessary pages.
|
807 |
+
|
808 |
+
Version 1.8.3 - Removes conversion process that attempted to convert listings made with versions 1.0 - 1.7 to the new 1.8 custom post type format
|
809 |
+
|
810 |
+
|
811 |
+
Version 1.8.2 - Fixes IE bug where "View" button does not work in listing excerpts
|
812 |
+
Fixes Missing argument 1 for wpbusdirman_the_listing_meta() bug
|
813 |
+
Fixes missing quote bug near img alt on a couple of lines
|
814 |
+
|
815 |
+
|
816 |
+
|
817 |
+
Version 1.8 of Business Directory Plugin makes use of WordPress 3.0+ custom post types. The way the plugin works has been completely changed to use custom post types. When you upgrade to version 1.8 it will convert your previous installation to the new format. The new format conversion is not guaranteed to work 100% so you are very strongly advised if you have listings in your directory presently to export those listings in case you might need to re-add them manually.
|
818 |
+
|
819 |
+
Plugin now uses a custom post type for posts related to the directory
|
820 |
+
|
821 |
+
Plugin now uses a custom category taxonomy for categories related to the directory
|
822 |
+
|
823 |
+
Plugin now uses a custom tags taxonomy for tags related to the directory listings
|
824 |
+
|
825 |
+
Plugin now allows for better integration with your theme. See the "Usage Doc" section for information on how to customize your theme to use the plugin functions.
|
826 |
+
|
827 |
+
Bug related to "Manage Fees" has been fixed. This bug resulted in admin being told payments were not turned on even though payments were in fact turned on.
|
828 |
+
|
829 |
+
|
830 |
+
|
831 |
+
== Upgrade Notice ==
|
832 |
+
|
833 |
+
1. If you are upgrading please export your current data first. There is always the possibility of something going wrong during the upgrading process. Failing to save your data before you upgrade can prove costly if something goes wrong and your data gets lost. Backup your database. Backup your files.
|
834 |
+
|
835 |
+
2. If you are not using WP 3.0 or above you should not install Business Directory Plugin.
|
836 |
+
|
837 |
+
3. If you are upgrading it is recommended that you do a manual upgrade rather than using the automatic upgrade option available via your dashboard. If you use the automatic upgrade option please, again, backup your data first.
|
838 |
+
|
839 |
+
== Usage Doc ==
|
840 |
+
|
841 |
+
For complete documentation on the plugin, please visit the [BD Documentation Site](http://businessdirectoryplugin.com/docs)
|
842 |
+
|
843 |
+
1. Setting up your categories
|
844 |
+
|
845 |
+
Go to your Dashboard and look for the "Directory" menu box. Listed under the Directory menu box are the links "Add New", "Categories" and "Tags". Click the "Categories" link and add your categories just the same way you would normally add categories under Posts->Categories.
|
846 |
+
|
847 |
+
2. Matching the design to your theme
|
848 |
+
|
849 |
+
Please visit this page for complete and up-to-date instructions on matching BD to your theme.
|
850 |
+
|
851 |
+
[How to match BD to your theme](http://businessdirectoryplugin.com/docs/matching-the-design-to-your-theme/)
|
852 |
+
|
853 |
+
3. Adding a menu of the directory categories
|
854 |
+
|
855 |
+
To add a menu of the directory categories to your theme use the code below:
|
856 |
+
<?php global $wpbdmposttypecategory; wp_list_categories('title_li=&taxonomy='.$wpbdmposttypecategory); ?>
|
857 |
+
You can filter the function the way you would normally filter wp_list_categories. Just make sure it includes 'taxonomy='.$wpbdmposttypecategory so that it knows you only want the plugin directory categories.
|
858 |
+
|
859 |
+
4. Adding a latest posts widget
|
860 |
+
|
861 |
+
NEW: BD now comes with 3 standard widgets--Latest Listings, Random Listings and Featured Listings. Place in any
|
862 |
+
widget-ready theme.
|
863 |
+
|
864 |
+
== Frequently Asked Questions ==
|
865 |
+
|
866 |
+
For the definitive FAQ section, please vist the [FAQ Section of the Forum](http://businessdirectoryplugin.com/support-forum/faq)
|
867 |
+
|
868 |
+
1. How do I setup my categories?
|
869 |
+
You setup your categories under the "Directory" menu tab that will appear in the dashboard menu when you install the plugin. Under the Directory menu tab there is a link "Categories". You click this and add your categories the same way you do with your normal WordPress blog.
|
870 |
+
|
871 |
+
2. Why isn't the email address showing up in the listings?
|
872 |
+
The email address is not showing up because it is being programmatically blocked. The reason for this is to protect the privacy of your users so that their email address does not appear for public viewing where email harvesting bots can grab them and add them to spam email lists.
|
873 |
+
|
874 |
+
3. Okay, I understand that the plugin is blocking the email address to protect the user's privacy, but I still prefer to display the email address in the listing pages. How can I do that?
|
875 |
+
To override the email block, go to the WPBusDirMan menu tab that appears in the dashboard menu. Click the "Manage Options" link. Look under "Miscellaneous settings". You will see an option "Override email Blocking?". Check that option and it should make the email address visible.
|
876 |
+
|
877 |
+
|
878 |
+
|
879 |
+
|
880 |
+
|
admin/admin-pages.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
function wpbdp_admin_sidebar() {
|
3 |
+
return wpbdp_render_page(WPBDP_PATH . 'admin/templates/sidebar.tpl.php');
|
4 |
+
}
|
5 |
+
|
6 |
+
function wpbdp_admin_header($title_ = null, $id = null, $h2items =array(), $sidebar = true) {
|
7 |
+
global $title;
|
8 |
+
|
9 |
+
if (!$title_) $title_ = $title;
|
10 |
+
return wpbdp_render_page( WPBDP_PATH . 'admin/templates/header.tpl.php', array( 'page_title' => $title_, 'page_id' => $id, 'h2items' => $h2items, 'sidebar' => $sidebar ) );
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
function wpbdp_admin_footer()
|
15 |
+
{
|
16 |
+
$html = '<!--</div>--></div><br class="clear" /></div>';
|
17 |
+
return $html;
|
18 |
+
}
|
19 |
+
|
admin/class-admin-listings.php
ADDED
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_Admin_Listings {
|
4 |
+
|
5 |
+
function __construct() {
|
6 |
+
add_action('admin_init', array($this, 'add_metaboxes'));
|
7 |
+
|
8 |
+
add_action( 'manage_' . WPBDP_POST_TYPE . '_posts_columns', array( &$this, 'add_columns' ) );
|
9 |
+
add_action( 'manage_' . WPBDP_POST_TYPE . '_posts_custom_column', array( &$this, 'listing_column' ), 10, 2 );
|
10 |
+
|
11 |
+
add_filter( 'views_edit-' . WPBDP_POST_TYPE, array( &$this, 'listing_views' ) );
|
12 |
+
add_filter( 'posts_clauses', array( &$this, 'listings_admin_filters' ) );
|
13 |
+
|
14 |
+
add_filter( 'post_row_actions', array( &$this, 'row_actions' ), 10, 2 );
|
15 |
+
|
16 |
+
add_action( 'save_post', array( &$this, 'save_post' ) );
|
17 |
+
|
18 |
+
add_action('admin_footer', array($this, '_add_bulk_actions'));
|
19 |
+
add_action('admin_footer', array($this, '_fix_new_links'));
|
20 |
+
}
|
21 |
+
|
22 |
+
function add_metaboxes() {
|
23 |
+
add_meta_box( 'BusinessDirectory_listinginfo',
|
24 |
+
__( 'Listing Information', 'WPBDM' ),
|
25 |
+
array( 'WPBDP_Admin_Listing_Metabox', 'metabox_callback' ),
|
26 |
+
WPBDP_POST_TYPE,
|
27 |
+
'side',
|
28 |
+
'core' );
|
29 |
+
|
30 |
+
add_meta_box( 'wpbdp-listing-fields',
|
31 |
+
_x( 'Listing Fields / Images', 'admin', 'WPBDM' ),
|
32 |
+
array( 'WPBDP_Admin_Listing_Fields_Metabox', 'metabox_callback' ),
|
33 |
+
WPBDP_POST_TYPE,
|
34 |
+
'normal',
|
35 |
+
'core' );
|
36 |
+
}
|
37 |
+
|
38 |
+
// {{{ Custom columns.
|
39 |
+
|
40 |
+
function add_columns( $columns_ ) {
|
41 |
+
$custom_columns = array();
|
42 |
+
$custom_columns['category'] = _x( 'Categories', 'admin', 'WPBDM' );
|
43 |
+
$custom_columns['payment_status'] = __( 'Payment Status', 'WPBDM' );
|
44 |
+
$custom_columns['sticky_status'] = __( 'Featured (Sticky) Status', 'WPBDM' );
|
45 |
+
|
46 |
+
$columns = array();
|
47 |
+
|
48 |
+
foreach ( $columns_ as $k => $v ) {
|
49 |
+
$columns[ $k ] = $v;
|
50 |
+
|
51 |
+
if ( 'title' == $k )
|
52 |
+
$columns = array_merge( $columns, $custom_columns );
|
53 |
+
}
|
54 |
+
|
55 |
+
return apply_filters( 'wpbdp_admin_directory_columns', $columns );
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
function listing_column( $column, $post_id ) {
|
60 |
+
if ( ! method_exists( $this, 'listing_column_' . $column ) )
|
61 |
+
return do_action( 'wpbdp_admin_directory_column_' . $column, $post_id );
|
62 |
+
|
63 |
+
call_user_func( array( &$this, 'listing_column_' . $column ), $post_id );
|
64 |
+
}
|
65 |
+
|
66 |
+
function listing_column_category( $post_id ) {
|
67 |
+
$listing = WPBDP_Listing::get( $post_id );
|
68 |
+
$categories = $listing->get_categories( 'all' );
|
69 |
+
|
70 |
+
$i = 0;
|
71 |
+
foreach ( $categories as &$category ) {
|
72 |
+
print $category->expired ? '<s>' : '';
|
73 |
+
printf( '<a href="%s" title="%s">%s</a>',
|
74 |
+
get_term_link( $category->id, WPBDP_CATEGORY_TAX ),
|
75 |
+
$category->expired ? _x( '(Listing expired in this category)', 'admin', 'WPBDM' ) : '',
|
76 |
+
$category->name );
|
77 |
+
print $category->expired ? '</s>' : '';
|
78 |
+
print ( ( $i + 1 ) != count( $categories ) ? ', ' : '' );
|
79 |
+
|
80 |
+
$i++;
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
function listing_column_payment_status( $post_id ) {
|
85 |
+
$listing = WPBDP_Listing::get( $post_id );
|
86 |
+
$paid_status = $listing->get_payment_status();
|
87 |
+
|
88 |
+
$status_links = '';
|
89 |
+
|
90 |
+
if ( $paid_status != 'ok' )
|
91 |
+
$status_links .= sprintf('<span><a href="%s">%s</a></span>',
|
92 |
+
add_query_arg( array( 'wpbdmaction' => 'setaspaid', 'post' => $post_id ) ),
|
93 |
+
__('Paid', 'WPBDM'));
|
94 |
+
|
95 |
+
printf( '<span class="tag paymentstatus %s">%s</span>', $paid_status, strtoupper( $paid_status ) );
|
96 |
+
|
97 |
+
if ( $status_links && current_user_can( 'administrator' ) )
|
98 |
+
printf( '<div class="row-actions"><b>%s:</b> %s</div>', __( 'Mark as', 'WPBDM' ), $status_links );
|
99 |
+
}
|
100 |
+
|
101 |
+
function listing_column_sticky_status( $post_id ) {
|
102 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
103 |
+
$sticky_info = $upgrades_api->get_info( $post_id );
|
104 |
+
|
105 |
+
echo sprintf('<span class="tag status %s">%s</span><br />',
|
106 |
+
str_replace(' ', '', $sticky_info->status),
|
107 |
+
$sticky_info->pending ? __('Pending Upgrade', 'WPBDM') : esc_attr($sticky_info->level->name) );
|
108 |
+
|
109 |
+
echo '<div class="row-actions">';
|
110 |
+
|
111 |
+
if ( current_user_can('administrator') ) {
|
112 |
+
if ( $sticky_info->upgradeable ) {
|
113 |
+
echo sprintf('<span><a href="%s">%s</a></span>',
|
114 |
+
add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->upgrade->id, 'post' => $post_id)),
|
115 |
+
'<b>↑</b> ' . sprintf(__('Upgrade to %s', 'WPBDM'), esc_attr($sticky_info->upgrade->name)) );
|
116 |
+
echo '<br />';
|
117 |
+
}
|
118 |
+
|
119 |
+
if ( $sticky_info->downgradeable ) {
|
120 |
+
echo sprintf('<span><a href="%s">%s</a></span>',
|
121 |
+
add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->downgrade->id, 'post' => $post_id)),
|
122 |
+
'<b>↓</b> ' . sprintf(__('Downgrade to %s', 'WPBDM'), esc_attr($sticky_info->downgrade->name)) );
|
123 |
+
}
|
124 |
+
} elseif ( current_user_can('contributor') && wpbdp_user_can( 'upgrade-to-sticky', $post_id ) ) {
|
125 |
+
echo sprintf('<span><a href="%s"><b>↑</b> %s</a></span>', wpbdp_get_page_link('upgradetostickylisting', $post_id), _x('Upgrade to Featured', 'admin actions', 'WPBDM'));
|
126 |
+
}
|
127 |
+
|
128 |
+
echo '</div>';
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
// }}}
|
133 |
+
|
134 |
+
// {{{ List views.
|
135 |
+
|
136 |
+
function listing_views( $views ) {
|
137 |
+
global $wpdb;
|
138 |
+
|
139 |
+
if ( ! current_user_can( 'administrator' ) && ! current_user_can( 'editor' ) ) {
|
140 |
+
if ( current_user_can( 'contributor' ) && isset( $views['mine'] ) )
|
141 |
+
return array( $views['mine'] );
|
142 |
+
|
143 |
+
return array();
|
144 |
+
}
|
145 |
+
|
146 |
+
$post_statuses = '\'' . join('\',\'', isset($_GET['post_status']) ? array($_GET['post_status']) : array('publish', 'draft', 'pending')) . '\'';
|
147 |
+
|
148 |
+
// $unpaid = $wpdb->get_var( $wpdb->prepare(
|
149 |
+
// "SELECT COUNT(DISTINCT p.ID) FROM {$wpdb->posts} p LEFT JOIN {$wpdb->prefix}wpbdp_payments ps ON p.ID = ps.listing_id
|
150 |
+
// WHERE p.post_type = %s AND p.post_status IN ({$post_statuses}) AND ps.status = %s",
|
151 |
+
// WPBDP_POST_TYPE,
|
152 |
+
// 'pending'
|
153 |
+
// ) );
|
154 |
+
$unpaid = $wpdb->get_var( $wpdb->prepare(
|
155 |
+
"SELECT COUNT(DISTINCT p.ID) FROM {$wpdb->posts} p LEFT JOIN {$wpdb->prefix}wpbdp_payments ps
|
156 |
+
ON (ps.listing_id = p.ID AND ps.status = %s) WHERE p.post_type = %s
|
157 |
+
AND p.post_status IN ({$post_statuses}) AND ps.status IS NOT NULL",
|
158 |
+
'pending',
|
159 |
+
WPBDP_POST_TYPE ) );
|
160 |
+
|
161 |
+
$paid = intval( $wpdb->get_var( $wpdb->prepare(
|
162 |
+
"SELECT COUNT(*) FROM {$wpdb->posts} p WHERE p.post_type = %s AND p.post_status IN ({$post_statuses})",
|
163 |
+
WPBDP_POST_TYPE ) ) ) - $unpaid;
|
164 |
+
|
165 |
+
$pending_upgrade = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id)
|
166 |
+
WHERE p.post_type = %s AND p.post_status IN ({$post_statuses}) AND ( (pm.meta_key = %s AND pm.meta_value = %s) )",
|
167 |
+
WPBDP_POST_TYPE,
|
168 |
+
'_wpbdp[sticky]',
|
169 |
+
'pending') );
|
170 |
+
$expired = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT p.ID) FROM {$wpdb->posts} p INNER JOIN {$wpdb->prefix}wpbdp_listing_fees lf ON lf.listing_id = p.ID WHERE lf.expires_on < %s",
|
171 |
+
current_time( 'mysql' ) ) );
|
172 |
+
|
173 |
+
$views['paid'] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
174 |
+
add_query_arg('wpbdmfilter', 'paid', remove_query_arg('post')),
|
175 |
+
wpbdp_getv($_REQUEST, 'wpbdmfilter') == 'paid' ? 'current' : '',
|
176 |
+
__('Paid', 'WPBDM'),
|
177 |
+
number_format_i18n($paid));
|
178 |
+
$views['unpaid'] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
179 |
+
add_query_arg('wpbdmfilter', 'unpaid', remove_query_arg('post')),
|
180 |
+
wpbdp_getv($_REQUEST, 'wpbdmfilter') == 'unpaid' ? 'current' : '',
|
181 |
+
__('Unpaid', 'WPBDM'),
|
182 |
+
number_format_i18n($unpaid));
|
183 |
+
$views['featured'] = sprintf('<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
184 |
+
add_query_arg('wpbdmfilter', 'pendingupgrade', remove_query_arg('post')),
|
185 |
+
wpbdp_getv($_REQUEST, 'wpbdmfilter') == 'pendingupgrade' ? 'current' : '',
|
186 |
+
__('Pending Upgrade', 'WPBDM'),
|
187 |
+
number_format_i18n($pending_upgrade));
|
188 |
+
$views['expired'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
189 |
+
add_query_arg( 'wpbdmfilter', 'expired', remove_query_arg( 'post' ) ),
|
190 |
+
wpbdp_getv( $_REQUEST, 'wpbdmfilter' ) == 'expired' ? 'current' : '' ,
|
191 |
+
_x( 'Expired', 'admin', 'WPBDM' ),
|
192 |
+
number_format_i18n( $expired )
|
193 |
+
);
|
194 |
+
|
195 |
+
$views = apply_filters( 'wpbdp_admin_directory_views', $views, $post_statuses );
|
196 |
+
|
197 |
+
return $views;
|
198 |
+
}
|
199 |
+
|
200 |
+
function listings_admin_filters( $pieces ) {
|
201 |
+
global $current_screen;
|
202 |
+
global $wpdb;
|
203 |
+
|
204 |
+
if ( ! is_admin() || ! isset( $_REQUEST['wpbdmfilter'] ) || 'edit-' . WPBDP_POST_TYPE != $current_screen->id )
|
205 |
+
return $pieces;
|
206 |
+
|
207 |
+
switch ( $_REQUEST['wpbdmfilter'] ) {
|
208 |
+
case 'expired':
|
209 |
+
$pieces['join'] = " LEFT JOIN {$wpdb->prefix}wpbdp_listing_fees ON {$wpdb->prefix}wpbdp_listing_fees.listing_id = {$wpdb->posts}.ID ";
|
210 |
+
$pieces['where'] = $wpdb->prepare( " AND {$wpdb->prefix}wpbdp_listing_fees.expires_on IS NOT NULL AND {$wpdb->prefix}wpbdp_listing_fees.expires_on < %s ", current_time( 'mysql' ) );
|
211 |
+
$pieces['groupby'] = " {$wpdb->posts}.ID ";
|
212 |
+
break;
|
213 |
+
case 'pendingupgrade':
|
214 |
+
$pieces['join'] = " LEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = {$wpdb->posts}.ID ";
|
215 |
+
$pieces['where'] = $wpdb->prepare( " AND pm.meta_key = %s AND pm.meta_value = %s ", '_wpbdp[sticky]', 'pending' );
|
216 |
+
break;
|
217 |
+
case 'paid':
|
218 |
+
$pieces['where'] .= $wpdb->prepare( " AND NOT EXISTS ( SELECT 1 FROM {$wpdb->prefix}wpbdp_payments WHERE {$wpdb->posts}.ID = {$wpdb->prefix}wpbdp_payments.listing_id AND ( {$wpdb->prefix}wpbdp_payments.status IS NULL OR {$wpdb->prefix}wpbdp_payments.status != %s ) )", 'pending' );
|
219 |
+
break;
|
220 |
+
case 'unpaid':
|
221 |
+
$pieces['join'] .= " LEFT JOIN {$wpdb->prefix}wpbdp_payments ON {$wpdb->posts}.ID = {$wpdb->prefix}wpbdp_payments.listing_id ";
|
222 |
+
$pieces['where'] .= $wpdb->prepare( " AND {$wpdb->prefix}wpbdp_payments.status = %s ", 'pending' );
|
223 |
+
$pieces['groupby'] .= " {$wpdb->posts}.ID ";
|
224 |
+
break;
|
225 |
+
default:
|
226 |
+
$pieces = apply_filters( 'wpbdp_admin_directory_filter', $pieces, $_REQUEST['wpbdmfilter'] );
|
227 |
+
break;
|
228 |
+
}
|
229 |
+
|
230 |
+
return $pieces;
|
231 |
+
}
|
232 |
+
|
233 |
+
// }}}
|
234 |
+
|
235 |
+
|
236 |
+
public function row_actions($actions, $post) {
|
237 |
+
if ($post->post_type == WPBDP_POST_TYPE && current_user_can('contributor')) {
|
238 |
+
if (wpbdp_user_can('edit', $post->ID))
|
239 |
+
$actions['edit'] = sprintf('<a href="%s">%s</a>',
|
240 |
+
wpbdp_get_page_link('editlisting', $post->ID),
|
241 |
+
_x('Edit Listing', 'admin actions', 'WPBDM'));
|
242 |
+
|
243 |
+
if (wpbdp_user_can('delete', $listing_id))
|
244 |
+
$actions['delete'] = sprintf('<a href="%s">%s</a>', wpbdp_get_page_link('deletelisting', $listing_id), _x('Delete Listing', 'admin actions', 'WPBDM'));
|
245 |
+
}
|
246 |
+
|
247 |
+
return $actions;
|
248 |
+
}
|
249 |
+
|
250 |
+
public function save_post($post_id) {
|
251 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
252 |
+
return;
|
253 |
+
|
254 |
+
// Handle listings saved admin-side.
|
255 |
+
if ( is_admin() && isset( $_POST['post_type'] ) && $_POST['post_type'] == WPBDP_POST_TYPE ) {
|
256 |
+
$listing = WPBDP_Listing::get( $post_id );
|
257 |
+
|
258 |
+
if ( ! $listing )
|
259 |
+
return;
|
260 |
+
|
261 |
+
$listing->fix_categories( true );
|
262 |
+
|
263 |
+
// Save custom fields.
|
264 |
+
//if ( isset( $_POST['wpbdp-listing-fields-nonce'] ) && wp_verify_nonce( $_POST['wpbdp-listing-fields-nonce'], plugin_basename( __FILE__ ) ) )
|
265 |
+
if ( isset( $_POST['wpbdp-listing-fields-nonce'] ) ) {
|
266 |
+
$formfields_api = wpbdp_formfields_api();
|
267 |
+
$listingfields = wpbdp_getv( $_POST, 'listingfields', array() );
|
268 |
+
|
269 |
+
foreach ( $formfields_api->find_fields( array( 'association' => 'meta' ) ) as $field ) {
|
270 |
+
if ( isset( $listingfields[ $field->get_id() ] ) ) {
|
271 |
+
$value = $field->convert_input( $listingfields[ $field->get_id() ] );
|
272 |
+
$field->store_value( $listing->get_id(), $value );
|
273 |
+
} else {
|
274 |
+
$field->store_value( $listing->get_id(), $field->convert_input( null ) );
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
if ( isset( $_POST['thumbnail_id'] ) )
|
279 |
+
$listing->set_thumbnail_id( $_POST['thumbnail_id'] );
|
280 |
+
}
|
281 |
+
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
public function _add_bulk_actions() {
|
286 |
+
if (!current_user_can('administrator'))
|
287 |
+
return;
|
288 |
+
|
289 |
+
if ($screen = get_current_screen()) {
|
290 |
+
if ($screen->id == 'edit-' . WPBDP_POST_TYPE) {
|
291 |
+
if (isset($_GET['post_type']) && $_GET['post_type'] == WPBDP_POST_TYPE) {
|
292 |
+
$bulk_actions = array('sep0' => '--',
|
293 |
+
'publish' => _x('Publish Listing', 'admin actions', 'WPBDM'),
|
294 |
+
'sep1' => '--',
|
295 |
+
'upgradefeatured' => _x('Upgrade to Featured', 'admin actions', 'WPBDM'),
|
296 |
+
'cancelfeatured' => _x('Downgrade to Normal', 'admin actions', 'WPBDM'),
|
297 |
+
'sep2' => '--',
|
298 |
+
'setaspaid' => _x('Mark as Paid', 'admin actions', 'WPBDM'),
|
299 |
+
'sep3' => '--',
|
300 |
+
'renewlisting' => _x( 'Renew Listing', 'admin actions', 'WPBDM' )
|
301 |
+
);
|
302 |
+
$bulk_actions = apply_filters( 'wpbdp_admin_directory_bulk_actions', $bulk_actions );
|
303 |
+
|
304 |
+
// the 'bulk_actions' filter doesn't really work for this until this bug is fixed: http://core.trac.wordpress.org/ticket/16031
|
305 |
+
echo '<script type="text/javascript">';
|
306 |
+
|
307 |
+
foreach ($bulk_actions as $action => $text) {
|
308 |
+
echo sprintf('jQuery(\'select[name="%s"]\').append(\'<option value="%s" data-uri="%s">%s</option>\');',
|
309 |
+
'action', 'listing-' . $action, add_query_arg('wpbdmaction', $action), $text);
|
310 |
+
echo sprintf('jQuery(\'select[name="%s"]\').append(\'<option value="%s" data-uri="%s">%s</option>\');',
|
311 |
+
'action2', 'listing-' . $action, add_query_arg('wpbdmaction', $action), $text);
|
312 |
+
}
|
313 |
+
|
314 |
+
echo '</script>';
|
315 |
+
}
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
public function _fix_new_links() {
|
321 |
+
// 'contributors' should still use the frontend to add listings (editors, authors and admins are allowed to add things directly)
|
322 |
+
// XXX: this is kind of hacky but is the best we can do atm, there aren't hooks to change add links
|
323 |
+
if (current_user_can('contributor') && isset($_GET['post_type']) && $_GET['post_type'] == WPBDP_POST_TYPE) {
|
324 |
+
echo '<script type="text/javascript">';
|
325 |
+
echo sprintf('jQuery(\'a.add-new-h2\').attr(\'href\', \'%s\');', wpbdp_get_page_link('add-listing'));
|
326 |
+
echo '</script>';
|
327 |
+
}
|
328 |
+
}
|
329 |
+
|
330 |
+
}
|
admin/class-admin.php
ADDED
@@ -0,0 +1,853 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'admin/admin-pages.php' );
|
3 |
+
require_once( WPBDP_PATH . 'admin/class-admin-listings.php' );
|
4 |
+
require_once( WPBDP_PATH . 'admin/fees.php' );
|
5 |
+
require_once( WPBDP_PATH . 'admin/form-fields.php' );
|
6 |
+
require_once( WPBDP_PATH . 'admin/payments.php' );
|
7 |
+
// require_once( WPBDP_PATH . 'admin/transactions.php' );
|
8 |
+
require_once( WPBDP_PATH . 'admin/csv-import.php' );
|
9 |
+
require_once( WPBDP_PATH . 'admin/csv-export.php' );
|
10 |
+
require_once( WPBDP_PATH . 'admin/listing-metabox.php' );
|
11 |
+
require_once( WPBDP_PATH . 'admin/class-listing-fields-metabox.php' );
|
12 |
+
require_once( WPBDP_PATH . 'admin/page-debug.php' );
|
13 |
+
|
14 |
+
if ( ! class_exists( 'WPBDP_Admin' ) ) {
|
15 |
+
|
16 |
+
class WPBDP_Admin {
|
17 |
+
|
18 |
+
public $messages = array();
|
19 |
+
|
20 |
+
function __construct() {
|
21 |
+
add_action('admin_init', array($this, 'handle_actions'));
|
22 |
+
add_action('admin_init', array($this, 'register_settings'));
|
23 |
+
|
24 |
+
add_action('admin_init', array($this, 'check_for_required_fields'));
|
25 |
+
add_action('admin_init', array($this, 'check_for_required_pages'));
|
26 |
+
add_action('admin_init', array($this, 'check_payments_possible'));
|
27 |
+
add_action('admin_notices', array($this, 'admin_notices'));
|
28 |
+
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
|
29 |
+
|
30 |
+
// Admin menu.
|
31 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
32 |
+
add_filter( 'custom_menu_order', '__return_true' );
|
33 |
+
add_filter( 'menu_order', array( &$this, 'admin_menu_reorder' ) );
|
34 |
+
|
35 |
+
add_filter('wp_dropdown_users', array($this, '_dropdown_users'));
|
36 |
+
|
37 |
+
add_filter( 'manage_edit-' . WPBDP_CATEGORY_TAX . '_columns', array( &$this, 'add_custom_taxonomy_columns' ) );
|
38 |
+
add_filter( 'manage_edit-' . WPBDP_TAGS_TAX . '_columns', array( &$this, 'tag_taxonomy_columns' ) );
|
39 |
+
add_action( 'manage_' . WPBDP_CATEGORY_TAX . '_custom_column', array( &$this, 'custom_taxonomy_columns' ), 10, 3 );
|
40 |
+
|
41 |
+
add_filter('wp_terms_checklist_args', array($this, '_checklist_args')); // fix issue #152
|
42 |
+
|
43 |
+
add_action( 'wp_ajax_wpbdp-formfields-reorder', array( &$this, 'ajax_formfields_reorder' ) );
|
44 |
+
|
45 |
+
add_action( 'wp_ajax_wpbdp-admin-fees-set-order', array( &$this, 'ajax_fees_set_order' ) );
|
46 |
+
add_action( 'wp_ajax_wpbdp-admin-fees-reorder', array( &$this, 'ajax_fees_reorder' ) );
|
47 |
+
|
48 |
+
add_action( 'wp_ajax_wpbdp-listing_set_expiration', array( &$this, 'ajax_listing_set_expiration' ) );
|
49 |
+
add_action( 'wp_ajax_wpbdp-listing_remove_category', array( &$this, 'ajax_listing_remove_category' ) );
|
50 |
+
add_action( 'wp_ajax_wpbdp-listing_change_fee', array( &$this, 'ajax_listing_change_fee' ) );
|
51 |
+
|
52 |
+
add_action( 'wp_ajax_wpbdp-renderfieldsettings', array( 'WPBDP_FormFieldsAdmin', '_render_field_settings' ) );
|
53 |
+
|
54 |
+
add_action( 'wp_ajax_wpbdp-create-main-page', array( &$this, 'ajax_create_main_page' ) );
|
55 |
+
add_action( 'wp_ajax_wpbdp-drip_subscribe', array( &$this, 'ajax_drip_subscribe' ) );
|
56 |
+
add_action( 'wp_ajax_wpbdp-set_site_tracking', 'WPBDP_SiteTracking::handle_ajax_response' );
|
57 |
+
|
58 |
+
$this->listings = new WPBDP_Admin_Listings();
|
59 |
+
$this->csv_export = new WPBDP_Admin_CSVExport();
|
60 |
+
$this->payments = new WPBDP_Admin_Payments();
|
61 |
+
$this->debug_page = new WPBDP_Admin_Debug_Page();
|
62 |
+
}
|
63 |
+
|
64 |
+
function enqueue_scripts() {
|
65 |
+
global $wpbdp;
|
66 |
+
global $pagenow;
|
67 |
+
|
68 |
+
$debug_on = $wpbdp->is_debug_on();
|
69 |
+
|
70 |
+
wp_enqueue_style( 'wpbdp-admin',
|
71 |
+
WPBDP_URL . 'admin/resources/admin' . ( ! $debug_on ? '.min' : '' ) . '.css');
|
72 |
+
wp_enqueue_style( 'thickbox' );
|
73 |
+
|
74 |
+
wp_enqueue_script( 'wpbdp-frontend-js',
|
75 |
+
WPBDP_URL . 'core/js/wpbdp' . ( ! $debug_on ? '.min' : '' ) . '.js',
|
76 |
+
array( 'jquery' ) );
|
77 |
+
wp_enqueue_script( 'wpbdp-admin-js',
|
78 |
+
WPBDP_URL . 'admin/resources/admin' . ( ! $debug_on ? '.min' : '' ) . '.js',
|
79 |
+
array( 'jquery', 'thickbox', 'jquery-ui-sortable' ) );
|
80 |
+
|
81 |
+
if ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) {
|
82 |
+
wp_enqueue_style( 'wpbdp-jquery-ui-css',
|
83 |
+
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/redmond/jquery-ui.css' );
|
84 |
+
wp_enqueue_script( 'jquery-ui-datepicker' );
|
85 |
+
wp_enqueue_style( 'wpbdp-listing-admin-metabox', WPBDP_URL . 'admin/css/listing-metabox.min.css' );
|
86 |
+
|
87 |
+
wp_enqueue_style( 'wpbdp-dnd-upload' );
|
88 |
+
wp_enqueue_script( 'wpbdp-admin-listing', WPBDP_URL . 'admin/js/listing.js', array( 'wpbdp-admin-js', 'wpbdp-dnd-upload' ) );
|
89 |
+
}
|
90 |
+
|
91 |
+
// Ask for site tracking if needed.
|
92 |
+
if ( ! wpbdp_get_option( 'tracking-on', false ) && get_option( 'wpbdp-show-tracking-pointer', 0 ) && current_user_can( 'administrator' ) ) {
|
93 |
+
wp_enqueue_style( 'wp-pointer' );
|
94 |
+
wp_enqueue_script( 'wp-pointer' );
|
95 |
+
add_action( 'admin_print_footer_scripts', 'WPBDP_SiteTracking::request_js' );
|
96 |
+
}
|
97 |
+
|
98 |
+
if ( current_user_can( 'administrator' ) && get_option( 'wpbdp-show-drip-pointer', 0 ) ) {
|
99 |
+
wp_enqueue_style( 'wp-pointer' );
|
100 |
+
wp_enqueue_script( 'wp-pointer' );
|
101 |
+
add_action( 'admin_print_footer_scripts', array( $this, 'drip_pointer' ) );
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* @since 3.4.1
|
107 |
+
*/
|
108 |
+
private function get_drip_api_info( $key = '' ) {
|
109 |
+
$info = array(
|
110 |
+
'url' => 'https://api.getdrip.com/v1',
|
111 |
+
'api_key' => 'usskquea6f3yipbcitys',
|
112 |
+
'account_id' => '4037583',
|
113 |
+
'campaign' => '4494091'
|
114 |
+
);
|
115 |
+
|
116 |
+
if ( array_key_exists( $key, $info ) )
|
117 |
+
return $info[ $key ];
|
118 |
+
|
119 |
+
return '';
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* @since 3.4.1
|
124 |
+
*/
|
125 |
+
public function drip_pointer() {
|
126 |
+
global $current_user;
|
127 |
+
get_currentuserinfo();
|
128 |
+
|
129 |
+
$js = '$.post( ajaxurl, { action: "wpbdp-drip_subscribe",
|
130 |
+
email: $( "#wpbdp-drip-pointer-email" ).val(),
|
131 |
+
nonce: "'. wp_create_nonce( 'drip pointer subscribe') .'",
|
132 |
+
subscribe: "%d" } );';
|
133 |
+
|
134 |
+
$content = '';
|
135 |
+
$content .= _x( 'Find out how to create a compelling, thriving business directory from scratch in this ridiculously actionable (and FREE) 5-part email course. Get a FREE premium module just for signing up.', 'drip pointer', 'WPBDM' ) . '<br /><br />';
|
136 |
+
$content .= '<label>';
|
137 |
+
$content .= '<b>' . _x( 'Email Address:', 'drip pointer', 'WPBDM' ) . '</b>';
|
138 |
+
$content .= '<br />';
|
139 |
+
$content .= '<input type="text" id="wpbdp-drip-pointer-email" value="' . esc_attr( $current_user->user_email ) . '" />';
|
140 |
+
$content .= '</label>';
|
141 |
+
|
142 |
+
wpbdp_admin_pointer( '#wpadminbar',
|
143 |
+
_x( 'Want to know the Secrets of Building an Awesome Business Directory?', 'drip pointer', 'WPBDM' ),
|
144 |
+
$content,
|
145 |
+
_x( 'Yes, please!', 'drip pointer', 'WPBDM' ),
|
146 |
+
sprintf( $js, 1 ),
|
147 |
+
_x( 'No, thanks', 'drip pointer', 'WPBDM' ),
|
148 |
+
sprintf( $js, 0 ) );
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* @since 3.5.3
|
153 |
+
*/
|
154 |
+
public function ajax_create_main_page() {
|
155 |
+
$nonce = isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : '';
|
156 |
+
|
157 |
+
if ( ! current_user_can( 'administrator' ) || ! $nonce || ! wp_verify_nonce( $nonce, 'create main page' ) )
|
158 |
+
exit();
|
159 |
+
|
160 |
+
if ( wpbdp_get_page_id( 'main' ) )
|
161 |
+
exit();
|
162 |
+
|
163 |
+
$page = array( 'post_status' => 'publish',
|
164 |
+
'post_title' => _x( 'Business Directory', 'admin', 'WPBDM' ),
|
165 |
+
'post_type' => 'page',
|
166 |
+
'post_content' => '[businessdirectory]' );
|
167 |
+
$page_id = wp_insert_post( $page );
|
168 |
+
|
169 |
+
if ( ! $page_id )
|
170 |
+
exit();
|
171 |
+
|
172 |
+
$res = new WPBDP_Ajax_Response();
|
173 |
+
$res->set_message( str_replace( '<a>',
|
174 |
+
'<a href="' . get_permalink( $page_id ) . '" target="_blank">',
|
175 |
+
_x( 'You\'re all set. Visit your new <a>Business Directory</a> page.', 'admin', 'WPBDM' ) ) );
|
176 |
+
$res->send();
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* @since 3.4.1
|
181 |
+
*/
|
182 |
+
public function ajax_drip_subscribe() {
|
183 |
+
global $current_user;
|
184 |
+
get_currentuserinfo();
|
185 |
+
|
186 |
+
$res = new WPBDP_Ajax_Response();
|
187 |
+
$subscribe = ( '1' == $_POST['subscribe'] ) ? true : false;
|
188 |
+
|
189 |
+
if ( ! get_option( 'wpbdp-show-drip-pointer', 0 ) || ! wp_verify_nonce( $_POST['nonce'], 'drip pointer subscribe' ) )
|
190 |
+
$res->send_error();
|
191 |
+
|
192 |
+
delete_option( 'wpbdp-show-drip-pointer' );
|
193 |
+
|
194 |
+
if ( $subscribe ) {
|
195 |
+
if ( ! filter_var( $_POST['email'], FILTER_VALIDATE_EMAIL ) )
|
196 |
+
$res->send_error();
|
197 |
+
|
198 |
+
// Make request to Drip.
|
199 |
+
$payload = array( 'status' => 'active',
|
200 |
+
'subscribers' => array( array(
|
201 |
+
'email' => $_POST['email'],
|
202 |
+
'utc_offset' => 660,
|
203 |
+
'double_optin' => false,
|
204 |
+
'starting_email_index' => 0,
|
205 |
+
'reactivate_if_subscribed' => true,
|
206 |
+
'custom_fields' => array( 'name' => $current_user->display_name,
|
207 |
+
'url' => get_bloginfo( 'url' ) )
|
208 |
+
) )
|
209 |
+
);
|
210 |
+
$url = sprintf( '%s/%s/campaigns/%s/subscribers',
|
211 |
+
$this->get_drip_api_info( 'url' ),
|
212 |
+
$this->get_drip_api_info( 'account_id' ),
|
213 |
+
$this->get_drip_api_info( 'campaign' ) );
|
214 |
+
|
215 |
+
if ( function_exists( 'curl_init' ) ) {
|
216 |
+
$ch = curl_init();
|
217 |
+
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
|
218 |
+
curl_setopt( $ch, CURLOPT_USERPWD, $this->get_drip_api_info( 'api_key' ) . ':' );
|
219 |
+
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" );
|
220 |
+
curl_setopt( $ch, CURLOPT_HEADER, false );
|
221 |
+
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
222 |
+
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
223 |
+
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) );
|
224 |
+
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $payload ) );
|
225 |
+
curl_setopt( $ch, CURLOPT_URL, $url );
|
226 |
+
$result = curl_exec( $ch );
|
227 |
+
curl_close( $ch );
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
$res->send();
|
232 |
+
}
|
233 |
+
|
234 |
+
function admin_menu() {
|
235 |
+
add_menu_page( _x( 'Business Directory Admin', 'admin menu', "WPBDM" ),
|
236 |
+
_x( 'Directory Admin', 'admin menu', 'WPBDM' ),
|
237 |
+
'administrator',
|
238 |
+
'wpbdp_admin',
|
239 |
+
array( &$this, 'main_menu' ),
|
240 |
+
WPBDP_URL . 'admin/resources/menuico.png' );
|
241 |
+
add_submenu_page('wpbdp_admin',
|
242 |
+
_x('Add New Listing', 'admin menu', 'WPBDM'),
|
243 |
+
_x('Add New Listing', 'admin menu', 'WPBDM'),
|
244 |
+
'administrator',
|
245 |
+
'wpbdp_add_listing',
|
246 |
+
'__return_null');
|
247 |
+
add_submenu_page('wpbdp_admin',
|
248 |
+
_x('Manage Options', 'admin menu', 'WPBDM'),
|
249 |
+
_x('Manage Options', 'admin menu', 'WPBDM'),
|
250 |
+
'administrator',
|
251 |
+
'wpbdp_admin_settings',
|
252 |
+
array($this, 'admin_settings'));
|
253 |
+
add_submenu_page('wpbdp_admin',
|
254 |
+
_x('Manage Fees', 'admin menu', 'WPBDM'),
|
255 |
+
_x('Manage Fees', 'admin menu', 'WPBDM'),
|
256 |
+
'administrator',
|
257 |
+
'wpbdp_admin_fees',
|
258 |
+
array('WPBDP_FeesAdmin', 'admin_menu_cb'));
|
259 |
+
add_submenu_page('wpbdp_admin',
|
260 |
+
_x('Manage Form Fields', 'admin menu', 'WPBDM'),
|
261 |
+
_x('Manage Form Fields', 'admin menu', 'WPBDM'),
|
262 |
+
'administrator',
|
263 |
+
'wpbdp_admin_formfields',
|
264 |
+
array('WPBDP_FormFieldsAdmin', 'admin_menu_cb'));
|
265 |
+
add_submenu_page('wpbdp_admin',
|
266 |
+
_x('All Listings', 'admin menu', 'WPBDM'),
|
267 |
+
_x('All Listings', 'admin menu', 'WPBDM'),
|
268 |
+
'administrator',
|
269 |
+
'wpbdp_all_listings',
|
270 |
+
'__return_false');
|
271 |
+
add_submenu_page('wpbdp_admin',
|
272 |
+
_x('Pending Upgrade', 'admin menu', 'WPBDM'),
|
273 |
+
_x('Pending Upgrade', 'admin menu', 'WPBDM'),
|
274 |
+
'administrator',
|
275 |
+
'wpbdp_manage_featured',
|
276 |
+
'__return_false');
|
277 |
+
add_submenu_page('wpbdp_admin',
|
278 |
+
_x('Pending Payment', 'admin menu', 'WPBDM'),
|
279 |
+
_x('Pending Payment', 'admin menu', 'WPBDM'),
|
280 |
+
'administrator',
|
281 |
+
'wpbdp_manage_payments',
|
282 |
+
'__return_false');
|
283 |
+
|
284 |
+
// if ( wpbdp_payments_api()->payments_possible() ) {
|
285 |
+
// add_submenu_page( 'wpbdp_admin',
|
286 |
+
// _x( 'Transactions', 'admin menu', 'WPBDM' ),
|
287 |
+
// _x( 'Transactions', 'admin menu', 'WPBDM' ),
|
288 |
+
// 'administrator',
|
289 |
+
// 'wpbdp_manage_transactions',
|
290 |
+
// array( 'WPBDP_TransactionsAdmin', 'admin_menu_cb' )
|
291 |
+
// );
|
292 |
+
// }
|
293 |
+
add_submenu_page('wpbdp_admin',
|
294 |
+
_x('CSV Import', 'admin menu', 'WPBDM'),
|
295 |
+
_x('CSV Import', 'admin menu', 'WPBDM'),
|
296 |
+
'administrator',
|
297 |
+
'wpbdp-csv-import',
|
298 |
+
array('WPBDP_CSVImportAdmin', 'admin_menu_cb'));
|
299 |
+
add_submenu_page( 'wpbdp_admin',
|
300 |
+
_x( 'CSV Export', 'admin menu', 'WPBDM' ),
|
301 |
+
_x( 'CSV Export', 'admin menu', 'WPBDM' ),
|
302 |
+
'administrator',
|
303 |
+
'wpbdp-csv-export',
|
304 |
+
array( &$this->csv_export, 'dispatch' ) );
|
305 |
+
add_submenu_page( 'wpbdp_admin',
|
306 |
+
_x( 'Debug', 'admin menu', 'WPBDM' ),
|
307 |
+
_x( 'Debug', 'admin menu', 'WPBDM' ),
|
308 |
+
'administrator',
|
309 |
+
'wpbdp-debug-info',
|
310 |
+
array( &$this->debug_page, 'dispatch' ) );
|
311 |
+
|
312 |
+
global $submenu;
|
313 |
+
|
314 |
+
if (current_user_can('administrator')) {
|
315 |
+
$submenu['wpbdp_admin'][1][2] = admin_url(sprintf('post-new.php?post_type=%s', WPBDP_POST_TYPE));
|
316 |
+
$submenu['wpbdp_admin'][0][0] = _x('Main Menu', 'admin menu', 'WPBDM');
|
317 |
+
$submenu['wpbdp_admin'][5][2] = admin_url( 'edit.php?post_type=' . WPBDP_POST_TYPE );
|
318 |
+
$submenu['wpbdp_admin'][6][2] = admin_url(sprintf('edit.php?post_type=%s&wpbdmfilter=%s', WPBDP_POST_TYPE, 'pendingupgrade'));
|
319 |
+
$submenu['wpbdp_admin'][7][2] = admin_url(sprintf('edit.php?post_type=%s&wpbdmfilter=%s', WPBDP_POST_TYPE, 'unpaid'));
|
320 |
+
} elseif (current_user_can('contributor')) {
|
321 |
+
$m = $submenu['edit.php?post_type=' . WPBDP_POST_TYPE];
|
322 |
+
$keys = array_keys($m);
|
323 |
+
$m[$keys[1]][2] = wpbdp_get_page_link('add-listing');
|
324 |
+
}
|
325 |
+
|
326 |
+
do_action('wpbdp_admin_menu', 'wpbdp_admin');
|
327 |
+
|
328 |
+
add_submenu_page('wpbdp_admin',
|
329 |
+
_x('Uninstall Business Directory Plugin', 'admin menu', 'WPBDM'),
|
330 |
+
_x('Uninstall', 'admin menu', 'WPBDM'),
|
331 |
+
'administrator',
|
332 |
+
'wpbdp_uninstall',
|
333 |
+
array($this, 'uninstall_plugin'));
|
334 |
+
}
|
335 |
+
|
336 |
+
function admin_menu_reorder( $menu_order ) {
|
337 |
+
$admin_index = array_search( 'wpbdp_admin', $menu_order, true );
|
338 |
+
$dir_index = array_search( 'edit.php?post_type=' . WPBDP_POST_TYPE, $menu_order, true );
|
339 |
+
|
340 |
+
if ( false === $admin_index || false === $dir_index )
|
341 |
+
return $menu_order;
|
342 |
+
|
343 |
+
$min_key = min( $admin_index, $dir_index );
|
344 |
+
|
345 |
+
$res = array();
|
346 |
+
foreach ( $menu_order as $i => $v ) {
|
347 |
+
if ( $i == $min_key ) {
|
348 |
+
$res[] = $menu_order[ $dir_index ];
|
349 |
+
$res[] = $menu_order[ $admin_index ];
|
350 |
+
continue;
|
351 |
+
} elseif ( $admin_index == $i || $dir_index == $i ) {
|
352 |
+
continue;
|
353 |
+
}
|
354 |
+
|
355 |
+
$res[] = $v;
|
356 |
+
}
|
357 |
+
|
358 |
+
return $res;
|
359 |
+
}
|
360 |
+
|
361 |
+
public function _checklist_args($args) {
|
362 |
+
$args['checked_ontop'] = false;
|
363 |
+
return $args;
|
364 |
+
}
|
365 |
+
|
366 |
+
public function ajax_formfields_reorder() {
|
367 |
+
$response = new WPBDP_Ajax_Response();
|
368 |
+
|
369 |
+
if ( ! current_user_can( 'administrator' ) )
|
370 |
+
$response->send_error();
|
371 |
+
|
372 |
+
$order = array_map( 'intval', isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : array() );
|
373 |
+
|
374 |
+
if ( ! $order )
|
375 |
+
$response->send_error();
|
376 |
+
|
377 |
+
global $wpbdp;
|
378 |
+
|
379 |
+
if ( ! $wpbdp->formfields->set_fields_order( $order ) )
|
380 |
+
$response->send_error();
|
381 |
+
|
382 |
+
$response->send();
|
383 |
+
}
|
384 |
+
|
385 |
+
public function ajax_fees_set_order() {
|
386 |
+
$nonce = isset( $_POST['_wpnonce'] ) ? $_POST['_wpnonce'] : '';
|
387 |
+
$order = isset( $_POST['fee_order'] ) ? $_POST['fee_order'] : false;
|
388 |
+
|
389 |
+
if ( ! wp_verify_nonce( $nonce, 'change fees order' ) || ! $order )
|
390 |
+
exit();
|
391 |
+
|
392 |
+
$res = new WPBDP_Ajax_Response();
|
393 |
+
wpbdp_set_option( 'fee-order', $order );
|
394 |
+
$res->send();
|
395 |
+
}
|
396 |
+
|
397 |
+
public function ajax_fees_reorder() {
|
398 |
+
global $wpdb;
|
399 |
+
|
400 |
+
$response = new WPBDP_Ajax_Response();
|
401 |
+
|
402 |
+
if ( ! current_user_can( 'administrator' ) )
|
403 |
+
$response->send_error();
|
404 |
+
|
405 |
+
$order = array_map( 'intval', isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : array() );
|
406 |
+
|
407 |
+
if ( ! $order )
|
408 |
+
$response->send_error();
|
409 |
+
|
410 |
+
$weight = count( $order ) - 1;
|
411 |
+
foreach( $order as $fee_id ) {
|
412 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_fees', array( 'weight' => $weight ), array( 'id' => $fee_id ) );
|
413 |
+
$weight--;
|
414 |
+
}
|
415 |
+
|
416 |
+
$response->send();
|
417 |
+
}
|
418 |
+
|
419 |
+
/*
|
420 |
+
* AJAX listing actions.
|
421 |
+
*/
|
422 |
+
public function ajax_listing_set_expiration() {
|
423 |
+
$response = new WPBDP_Ajax_Response();
|
424 |
+
|
425 |
+
$renewal_id = intval( isset( $_POST['renewal_id'] ) ? $_POST['renewal_id'] : 0 );
|
426 |
+
$expiration_time = isset( $_POST['expiration_date'] ) ? date( 'Y-m-d 00:00:00', strtotime( trim( $_POST['expiration_date'] ) ) ) : '';
|
427 |
+
|
428 |
+
if ( ! $renewal_id || ! $expiration_time || ! current_user_can( 'administrator' ) )
|
429 |
+
$response->send_error();
|
430 |
+
|
431 |
+
global $wpdb;
|
432 |
+
|
433 |
+
if ( $expiration_time )
|
434 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}wpbdp_listing_fees SET expires_on = %s, email_sent = %d WHERE id = %d", $expiration_time, 0, $renewal_id ) );
|
435 |
+
|
436 |
+
$response->add( 'formattedExpirationDate', date_i18n( get_option( 'date_format' ), strtotime( $expiration_time ) ) );
|
437 |
+
$response->send();
|
438 |
+
}
|
439 |
+
|
440 |
+
public function ajax_listing_remove_category() {
|
441 |
+
$response = new WPBDP_Ajax_Response();
|
442 |
+
|
443 |
+
$listing = WPBDP_Listing::get( intval( isset( $_POST['listing'] ) ? $_POST['listing'] : 0 ) );
|
444 |
+
$category = intval( isset( $_POST['category'] ) ? $_POST['category'] : 0 );
|
445 |
+
if ( ! $listing || ! $category )
|
446 |
+
$response->send_error();
|
447 |
+
|
448 |
+
$listing->remove_category( $category );
|
449 |
+
$response->send();
|
450 |
+
}
|
451 |
+
|
452 |
+
public function ajax_listing_change_fee() {
|
453 |
+
global $wpdb;
|
454 |
+
|
455 |
+
$response = new WPBDP_Ajax_Response();
|
456 |
+
|
457 |
+
if ( ! current_user_can( 'administrator' ) )
|
458 |
+
$response->send_error();
|
459 |
+
|
460 |
+
$fee_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", isset( $_POST['renewal'] ) ? $_POST['renewal'] : 0 ) );
|
461 |
+
|
462 |
+
if ( ! $fee_info )
|
463 |
+
$response->send_error();
|
464 |
+
|
465 |
+
$listing = WPBDP_Listing::get( $fee_info->listing_id );
|
466 |
+
$category = $listing->get_category_info( $fee_info->category_id );
|
467 |
+
|
468 |
+
if ( ! $listing || ! $category || 'pending' == $category->status )
|
469 |
+
$response->send_error();
|
470 |
+
|
471 |
+
$response->add( 'html', wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-change-fee.tpl.php',
|
472 |
+
array( 'category' => $category,
|
473 |
+
'listing' => $listing,
|
474 |
+
'fees' => wpbdp_get_fees_for_category( $fee_info->category_id ) ) ) );
|
475 |
+
$response->send();
|
476 |
+
}
|
477 |
+
|
478 |
+
function admin_notices() {
|
479 |
+
if ( ! current_user_can( 'administrator' ) )
|
480 |
+
return;
|
481 |
+
|
482 |
+
$this->check_compatibility();
|
483 |
+
$this->check_setup();
|
484 |
+
|
485 |
+
foreach ($this->messages as $msg) {
|
486 |
+
if (is_array($msg)) {
|
487 |
+
echo sprintf('<div class="%s"><p>%s</p></div>', $msg[1], $msg[0]);
|
488 |
+
} else {
|
489 |
+
echo sprintf('<div class="updated"><p>%s</p></div>', $msg);
|
490 |
+
}
|
491 |
+
}
|
492 |
+
|
493 |
+
$this->messages = array();
|
494 |
+
}
|
495 |
+
|
496 |
+
function handle_actions() {
|
497 |
+
if (!isset($_REQUEST['wpbdmaction']) || !isset($_REQUEST['post']))
|
498 |
+
return;
|
499 |
+
|
500 |
+
$action = $_REQUEST['wpbdmaction'];
|
501 |
+
$posts = is_array($_REQUEST['post']) ? $_REQUEST['post'] : array($_REQUEST['post']);
|
502 |
+
|
503 |
+
$listings_api = wpbdp_listings_api();
|
504 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
505 |
+
|
506 |
+
if (!current_user_can('administrator'))
|
507 |
+
exit;
|
508 |
+
|
509 |
+
switch ($action) {
|
510 |
+
case 'publish':
|
511 |
+
foreach ($posts as $post_id) {
|
512 |
+
wp_update_post( array( 'ID' => $post_id, 'post_status' => 'publish' ) );
|
513 |
+
}
|
514 |
+
|
515 |
+
$this->messages[] = _nx('The listing has been published.',
|
516 |
+
'The listings have been published.',
|
517 |
+
count($posts),
|
518 |
+
'admin',
|
519 |
+
'WPBDM');
|
520 |
+
break;
|
521 |
+
|
522 |
+
case 'setaspaid':
|
523 |
+
foreach ($posts as $post_id) {
|
524 |
+
$listing = WPBDP_Listing::get( $post_id );
|
525 |
+
$listing->mark_as_paid();
|
526 |
+
}
|
527 |
+
|
528 |
+
$this->messages[] = _nx('The listing status has been set as paid.',
|
529 |
+
'The listings status has been set as paid.',
|
530 |
+
count($posts),
|
531 |
+
'admin',
|
532 |
+
'WPBDM');
|
533 |
+
break;
|
534 |
+
|
535 |
+
case 'changesticky':
|
536 |
+
foreach ( $posts as $post_id ):
|
537 |
+
$upgrades_api->set_sticky( $post_id, wpbdp_getv($_GET, 'u') );
|
538 |
+
endforeach;
|
539 |
+
|
540 |
+
$this->messages[] = _nx('The listing has been modified.',
|
541 |
+
'The listings have been modified.',
|
542 |
+
count($posts),
|
543 |
+
'admin',
|
544 |
+
'WPBDM');
|
545 |
+
|
546 |
+
break;
|
547 |
+
|
548 |
+
case 'upgradefeatured':
|
549 |
+
foreach ( $posts as $post_id ):
|
550 |
+
$upgrades_api->set_sticky( $post_id, 'sticky', true );
|
551 |
+
endforeach;
|
552 |
+
|
553 |
+
$this->messages[] = _nx('The listing has been upgraded.',
|
554 |
+
'The listings have been upgraded.',
|
555 |
+
count($posts),
|
556 |
+
'admin',
|
557 |
+
'WPBDM');
|
558 |
+
break;
|
559 |
+
|
560 |
+
case 'cancelfeatured':
|
561 |
+
foreach ($posts as $post_id ):
|
562 |
+
$upgrades_api->set_sticky( $post_id, 'normal' );
|
563 |
+
endforeach;
|
564 |
+
|
565 |
+
$this->messages[] = _nx('The listing has been downgraded.',
|
566 |
+
'The listings have been downgraded.',
|
567 |
+
count($posts),
|
568 |
+
'admin',
|
569 |
+
'WPBDM');
|
570 |
+
break;
|
571 |
+
|
572 |
+
case 'approvetransaction':
|
573 |
+
$transaction = WPBDP_Payment::get( $_GET['transaction_id'] );
|
574 |
+
$transaction->set_status( WPBDP_Payment::STATUS_COMPLETED, 'admin' );
|
575 |
+
$transaction->save();
|
576 |
+
|
577 |
+
$this->messages[] = _x( 'The transaction has been approved.', 'admin', 'WPBDM' );
|
578 |
+
break;
|
579 |
+
|
580 |
+
case 'rejecttransaction':
|
581 |
+
$transaction = WPBDP_Payment::get( $_GET['transaction_id'] );
|
582 |
+
$transaction->set_status( WPBDP_Payment::STATUS_REJECTED, 'admin' );
|
583 |
+
$transaction->save();
|
584 |
+
|
585 |
+
$this->messages[] = _x( 'The transaction has been rejected.', 'admin', 'WPBDM' );
|
586 |
+
break;
|
587 |
+
|
588 |
+
case 'assignfee':
|
589 |
+
$listing = WPBDP_Listing::get( $posts[0] );
|
590 |
+
$listing->add_category( $_GET['category_id'], $_GET['fee_id'] );
|
591 |
+
$this->messages[] = _x('The fee was successfully assigned.', 'admin', 'WPBDM');
|
592 |
+
|
593 |
+
break;
|
594 |
+
|
595 |
+
case 'renewlisting':
|
596 |
+
foreach ( $posts as $post_id ):
|
597 |
+
$listings_api->auto_renew( $post_id );
|
598 |
+
endforeach;
|
599 |
+
|
600 |
+
$this->messages[] = _nx( 'Listing was renewed.', 'Listings were renewed.', count( $posts ), 'admin', 'WPBDM' );
|
601 |
+
break;
|
602 |
+
|
603 |
+
case 'send-renewal-email':
|
604 |
+
$renewal_id = intval( $_GET['renewal_id'] );
|
605 |
+
|
606 |
+
if ( $listings_api->send_renewal_email( $renewal_id ) )
|
607 |
+
$this->messages[] = _x( 'Renewal email sent.', 'admin', 'WPBDM' );
|
608 |
+
|
609 |
+
break;
|
610 |
+
|
611 |
+
default:
|
612 |
+
do_action( 'wpbdp_admin_directory_handle_action', $action );
|
613 |
+
break;
|
614 |
+
}
|
615 |
+
|
616 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array('wpbdmaction', 'wpbdmfilter', 'transaction_id', 'category_id', 'fee_id', 'u', 'renewal_id'), $_SERVER['REQUEST_URI'] );
|
617 |
+
}
|
618 |
+
|
619 |
+
public function _dropdown_users($output) {
|
620 |
+
global $post;
|
621 |
+
|
622 |
+
if (is_admin() && get_post_type($post) == WPBDP_POST_TYPE) {
|
623 |
+
remove_filter('wp_dropdown_users', array($this, '_dropdown_users'));
|
624 |
+
$select = wp_dropdown_users(array(
|
625 |
+
'echo' => false,
|
626 |
+
'name' => 'post_author',
|
627 |
+
'selected' => !empty($post->ID) ? $post->post_author : wp_get_current_user()->ID,
|
628 |
+
'include_selected' => true,
|
629 |
+
'who' => 'all'
|
630 |
+
));
|
631 |
+
add_filter('wp_dropdown_users', array($this, '_dropdown_users'));
|
632 |
+
return $select;
|
633 |
+
|
634 |
+
}
|
635 |
+
|
636 |
+
return $output;
|
637 |
+
}
|
638 |
+
|
639 |
+
public function add_custom_taxonomy_columns( $cols ) {
|
640 |
+
$newcols = array_merge( array_slice( $cols, 0, 1 ),
|
641 |
+
array( 'id' => _x( 'ID', 'admin category id', 'WPBDM' ) ),
|
642 |
+
array_slice( $cols, 1, -1),
|
643 |
+
array( 'posts' => _x('Listing Count', 'admin', 'WPBDM') ) );
|
644 |
+
return $newcols;
|
645 |
+
}
|
646 |
+
|
647 |
+
public function tag_taxonomy_columns( $cols ) {
|
648 |
+
$newcols = array_merge( array_slice( $cols, 0, -1 ),
|
649 |
+
array( 'posts' => _x('Listing Count', 'admin', 'WPBDM') ) );
|
650 |
+
return $newcols;
|
651 |
+
}
|
652 |
+
|
653 |
+
public function custom_taxonomy_columns( $value, $column_name, $id ) {
|
654 |
+
if ( $column_name == 'id' )
|
655 |
+
return $id;
|
656 |
+
|
657 |
+
return $value;
|
658 |
+
}
|
659 |
+
|
660 |
+
|
661 |
+
/* Settings page */
|
662 |
+
public function register_settings() {
|
663 |
+
global $wpbdp;
|
664 |
+
$wpbdp->settings->register_in_admin();
|
665 |
+
}
|
666 |
+
|
667 |
+
public function admin_settings() {
|
668 |
+
global $wpbdp;
|
669 |
+
|
670 |
+
flush_rewrite_rules(false);
|
671 |
+
|
672 |
+
if (isset($_REQUEST['resetdefaults']) && intval($_REQUEST['resetdefaults']) == 1) {
|
673 |
+
$wpbdp->settings->reset_defaults();
|
674 |
+
$_REQUEST['settings-updated'] = true;
|
675 |
+
$_REQUEST['groupid'] = 'general';
|
676 |
+
unset($_REQUEST['resetdefaults']);
|
677 |
+
}
|
678 |
+
|
679 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( 'deletedb', $_SERVER['REQUEST_URI'] );
|
680 |
+
|
681 |
+
wpbdp_render_page(WPBDP_PATH . 'admin/templates/settings.tpl.php',
|
682 |
+
array('wpbdp_settings' => $wpbdp->settings),
|
683 |
+
true);
|
684 |
+
}
|
685 |
+
|
686 |
+
/* Uninstall. */
|
687 |
+
public function uninstall_plugin() {
|
688 |
+
global $wpdb;
|
689 |
+
|
690 |
+
$nonce = isset( $_POST['_wpnonce'] ) ? trim( $_POST['_wpnonce'] ) : '';
|
691 |
+
|
692 |
+
if ( $nonce && wp_verify_nonce( $nonce, 'uninstall bd' ) ) {
|
693 |
+
$installer = new WPBDP_Installer();
|
694 |
+
|
695 |
+
// Delete listings.
|
696 |
+
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_type = %s", WPBDP_POST_TYPE ) );
|
697 |
+
|
698 |
+
foreach ( $post_ids as $post_id )
|
699 |
+
wp_delete_post( $post_id, true );
|
700 |
+
|
701 |
+
// Drop tables.
|
702 |
+
$tables = array_keys( $installer->get_database_schema() );
|
703 |
+
foreach ( $tables as &$table ) {
|
704 |
+
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpbdp_{$table}" );
|
705 |
+
}
|
706 |
+
|
707 |
+
// Delete options.
|
708 |
+
delete_option( 'wpbdp-db-version' );
|
709 |
+
delete_option( 'wpbusdirman_db_version' );
|
710 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", 'wpbdp%' ) );
|
711 |
+
|
712 |
+
// Clear scheduled hooks.
|
713 |
+
wp_clear_scheduled_hook('wpbdp_listings_expiration_check');
|
714 |
+
|
715 |
+
$tracking = new WPBDP_SiteTracking();
|
716 |
+
$tracking->track_uninstall( isset( $_POST['uninstall'] ) ? $_POST['uninstall'] : null );
|
717 |
+
|
718 |
+
// Deactivate plugin.
|
719 |
+
$real_path = WPBDP_PATH . 'business-directory-plugin.php';
|
720 |
+
// if the plugin directory is a symlink, plugin_basename will return
|
721 |
+
// the real path, which may not be the same path WP associated to
|
722 |
+
// the plugin. Plugin paths must be of the form:
|
723 |
+
// wp-content/plugins/plugin-directory/plugin-file.php
|
724 |
+
$fixed_path = WP_CONTENT_DIR . '/plugins/' . basename(dirname($real_path)) . '/' . basename($real_path);
|
725 |
+
deactivate_plugins($fixed_path, true);
|
726 |
+
|
727 |
+
echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/uninstall-complete.tpl.php');
|
728 |
+
} else {
|
729 |
+
echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/uninstall-confirm.tpl.php');
|
730 |
+
}
|
731 |
+
}
|
732 |
+
|
733 |
+
/* Required fields check. */
|
734 |
+
public function check_for_required_fields() {
|
735 |
+
global $wpbdp;
|
736 |
+
|
737 |
+
if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wpbdp_admin_formfields' &&
|
738 |
+
isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'createrequired' ) {
|
739 |
+
// do not display the warning inside the page creating the required fields
|
740 |
+
return;
|
741 |
+
}
|
742 |
+
|
743 |
+
if ( $missing = $wpbdp->formfields->get_missing_required_fields() ) {
|
744 |
+
if (count($missing) > 1) {
|
745 |
+
$message = sprintf(_x('<b>Business Directory Plugin</b> requires fields with the following associations in order to work correctly: <b>%s</b>.', 'admin', 'WPBDM'), join(', ', $missing));
|
746 |
+
} else {
|
747 |
+
$message = sprintf(_x('<b>Business Directory Plugin</b> requires a field with a <b>%s</b> association in order to work correctly.', 'admin', 'WPBDM'), array_pop( $missing ) );
|
748 |
+
}
|
749 |
+
|
750 |
+
$message .= '<br />';
|
751 |
+
$message .= _x('You can create these custom fields by yourself inside "Manage Form Fields" or let Business Directory do this for you automatically.', 'admin', 'WPBDM');
|
752 |
+
$message .= '<br /><br />';
|
753 |
+
$message .= sprintf('<a href="%s">%s</a> | ',
|
754 |
+
admin_url('admin.php?page=wpbdp_admin_formfields'),
|
755 |
+
_x('Go to "Manage Form Fields"', 'admin', 'WPBDM'));
|
756 |
+
$message .= sprintf('<a href="%s">%s</a>',
|
757 |
+
admin_url('admin.php?page=wpbdp_admin_formfields&action=createrequired'),
|
758 |
+
_x('Create these required fields for me', 'admin', 'WPBDM'));
|
759 |
+
|
760 |
+
$this->messages[] = array($message, 'error');
|
761 |
+
}
|
762 |
+
}
|
763 |
+
|
764 |
+
/* Required pages check. */
|
765 |
+
public function check_for_required_pages() {
|
766 |
+
if ( ! wpbdp_get_page_id( 'main' ) && current_user_can( 'administrator' ) ) {
|
767 |
+
$message = _x('<b>Business Directory Plugin</b> requires a page with the <tt>[businessdirectory]</tt> shortcode to function properly.', 'admin', 'WPBDM');
|
768 |
+
$message .= '<br />';
|
769 |
+
$message .= _x('You can create this page by yourself or let Business Directory do this for you automatically.', 'admin', 'WPBDM');
|
770 |
+
$message .= '<p>';
|
771 |
+
$message .= sprintf( '<a href="#" class="button wpbdp-create-main-page-button" data-nonce="%s">%s</a>',
|
772 |
+
wp_create_nonce( 'create main page' ),
|
773 |
+
_x( 'Create required pages for me', 'admin', 'WPBDM' ) );
|
774 |
+
$message .= '</p>';
|
775 |
+
|
776 |
+
$this->messages[] = array($message, 'error');
|
777 |
+
}
|
778 |
+
}
|
779 |
+
|
780 |
+
/* Check if payments are enabled but no gateway available. */
|
781 |
+
public function check_payments_possible() {
|
782 |
+
// show messages only in directory admin pages
|
783 |
+
if ( (isset($_GET['post_type']) && $_GET['post_type'] == WPBDP_POST_TYPE) ||
|
784 |
+
(isset($_GET['page']) && stripos($_GET['page'], 'wpbdp_') !== FALSE) ) {
|
785 |
+
|
786 |
+
if ($errors = wpbdp_payments_api()->check_config()) {
|
787 |
+
foreach ($errors as $error) $this->messages[] = array($error, 'error');
|
788 |
+
}
|
789 |
+
}
|
790 |
+
}
|
791 |
+
|
792 |
+
private function check_compatibility() {
|
793 |
+
global $wpbdp;
|
794 |
+
|
795 |
+
$modules_msg = '';
|
796 |
+
$modules = $wpbdp->get_premium_modules_data();
|
797 |
+
|
798 |
+
foreach ( $modules as $module_id => &$module_info ) {
|
799 |
+
if ( $module_info['installed'] && version_compare( $module_info['version'], $module_info['required'], '<' ) ) {
|
800 |
+
$modules_msg .= '<li class="module-info">';
|
801 |
+
$modules_msg .= 'business-directory-<b>' . $module_id . '</b><br />';
|
802 |
+
$modules_msg .= '<span class="module-version">';
|
803 |
+
$modules_msg .= sprintf( _x( 'Installed: %s', 'admin compat', 'WPBDM' ), '<b>' . ( null === $module_info['version'] ? _x( 'N/A', 'admin compat', 'WPBDM' ) : $module_info['version'] ) . '</b>' );
|
804 |
+
$modules_msg .= '</span> -- ';
|
805 |
+
$modules_msg .= '<span class="module-required">';
|
806 |
+
$modules_msg .= sprintf( _x( 'Required: %s', 'admin compat', 'WPBDM' ), '<b>' . $module_info['required'] . '</b>' );
|
807 |
+
$modules_msg .= '</span>';
|
808 |
+
$modules_msg .= '</li>';
|
809 |
+
|
810 |
+
/* $modules_msg .= sprintf( _x( '• %s (installed: %s, required: %s).', 'admin compat', 'WPBDM' ),
|
811 |
+
'<span class="module-name">business-directory-<b>' . $module_id . '</b></span>',
|
812 |
+
'<span class="module-version">' . ( null === $module_info['version'] ? _x( 'N/A', 'admin compat', 'WPBDM' ) : $module_info['version'] ) . '</span>',
|
813 |
+
'<span class="module-required">' . $module_info['required'] . '</span>' );*/
|
814 |
+
}
|
815 |
+
}
|
816 |
+
|
817 |
+
if ( $modules_msg ) {
|
818 |
+
$message = '';
|
819 |
+
$message .= _x( 'Business Directory has detected some incompatible premium module versions installed.', 'admin compat', 'WPBDM' );
|
820 |
+
$message .= '<br />';
|
821 |
+
$message .= _x( 'Please upgrade to the required versions indicated below to make sure everything functions properly.', 'admin compat', 'WPBDM' );
|
822 |
+
$message .= '<ul class="wpbdp-module-compat-check">';
|
823 |
+
$message .= $modules_msg;
|
824 |
+
$message .= '</ul>';
|
825 |
+
|
826 |
+
$this->messages[] = array( $message, 'error' );
|
827 |
+
}
|
828 |
+
}
|
829 |
+
|
830 |
+
public function check_setup() {
|
831 |
+
global $pagenow;
|
832 |
+
|
833 |
+
if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] == 'wpbdp_admin_settings' ) {
|
834 |
+
if ( wpbdp_get_option( 'require-login' ) && !get_option( 'users_can_register' ) ) {
|
835 |
+
$this->messages[] = array(
|
836 |
+
str_replace( array( '[', ']' ), array( '<a href="' . admin_url( 'options-general.php' ) . '">', '</a>' ), _x( 'We noticed you want your Business Directory users to register before posting listings, but Registration for your site is currently disabled. Go [here] and check "Anyone can register" to make sure BD works properly.', 'admin', 'WPBDM' ) ),
|
837 |
+
'error' );
|
838 |
+
}
|
839 |
+
}
|
840 |
+
}
|
841 |
+
|
842 |
+
public function main_menu() {
|
843 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/home.tpl.php' );
|
844 |
+
}
|
845 |
+
|
846 |
+
}
|
847 |
+
|
848 |
+
function wpbdp_admin_message( $msg, $kind = '' ) {
|
849 |
+
global $wpbdp;
|
850 |
+
$wpbdp->admin->messages[] = $kind ? array( $msg, $kind ) : $msg;
|
851 |
+
}
|
852 |
+
|
853 |
+
}
|
admin/class-listing-fields-metabox.php
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPBDP_Admin_Listing_Fields_Metabox {
|
3 |
+
private $listing = null;
|
4 |
+
|
5 |
+
public function __construct( &$listing ) {
|
6 |
+
$this->listing = $listing;
|
7 |
+
}
|
8 |
+
|
9 |
+
public function render() {
|
10 |
+
$this->listing_fields();
|
11 |
+
$this->listing_images();
|
12 |
+
}
|
13 |
+
|
14 |
+
private function listing_fields() {
|
15 |
+
$formfields_api = wpbdp_formfields_api();
|
16 |
+
$post_values = wpbdp_getv( $_POST, 'listingfields', array() );
|
17 |
+
|
18 |
+
echo wp_nonce_field( plugin_basename( __FILE__ ), 'wpbdp-listing-fields-nonce' );
|
19 |
+
|
20 |
+
echo '<div style="border-bottom: solid 1px #dedede; padding-bottom: 10px;">';
|
21 |
+
echo sprintf( '<strong>%s</strong>', _x( 'Listing Fields', 'admin', 'WPBDM' ) );
|
22 |
+
echo '<div style="padding-left: 10px;">';
|
23 |
+
foreach ($formfields_api->find_fields( array( 'association' => 'meta' ) ) as $field ) {
|
24 |
+
$value = isset( $post_values[ $field->get_id() ] ) ? $field->convert_input( $post_values[ $field->get_id() ] ) : $field->value( $this->listing->get_id() );
|
25 |
+
echo $field->render( $value, 'admin-submit' );
|
26 |
+
}
|
27 |
+
echo '</div>';
|
28 |
+
echo '</div>';
|
29 |
+
echo '<div class="clear"></div>';
|
30 |
+
}
|
31 |
+
|
32 |
+
private function listing_images() {
|
33 |
+
if ( ! current_user_can( 'edit_posts' ) )
|
34 |
+
return;
|
35 |
+
|
36 |
+
$images = $this->listing->get_images( 'ids' );
|
37 |
+
$thumbnail_id = $this->listing->get_thumbnail_id();
|
38 |
+
|
39 |
+
// Current images.
|
40 |
+
echo '<h4>' . _x( 'Current Images', 'templates', 'WPBDM' ) . '</h4>';
|
41 |
+
echo '<div id="no-images-message" style="' . ( $images ? 'display: none;' : '' ) . '">' . _x( 'There are no images currently attached to the listing.', 'templates', 'WPBDM' ) . '</div>';
|
42 |
+
echo '<div id="wpbdp-uploaded-images" class="cf">';
|
43 |
+
|
44 |
+
foreach ( $images as $image_id ):
|
45 |
+
echo wpbdp_render( 'submit-listing/images-single',
|
46 |
+
array( 'image_id' => $image_id,
|
47 |
+
'is_thumbnail' => ( 1 == count( $images ) || $thumbnail_id == $image_id ) ),
|
48 |
+
false );
|
49 |
+
endforeach;
|
50 |
+
echo '</div>';
|
51 |
+
|
52 |
+
echo wpbdp_render( 'submit-listing/images-upload-form',
|
53 |
+
array( 'admin' => true, 'listing_id' => $this->listing->get_id() ),
|
54 |
+
false );
|
55 |
+
}
|
56 |
+
|
57 |
+
public static function metabox_callback( $post ) {
|
58 |
+
$listing = WPBDP_Listing::get( $post->ID );
|
59 |
+
|
60 |
+
if ( ! $listing )
|
61 |
+
return '';
|
62 |
+
|
63 |
+
$instance = new self( $listing );
|
64 |
+
return $instance->render();
|
65 |
+
}
|
66 |
+
}
|
admin/css/listing-metabox.css
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Listing metabox styles.
|
3 |
+
* @since 3.4
|
4 |
+
*/
|
5 |
+
|
6 |
+
#BusinessDirectory_listinginfo .inside {
|
7 |
+
margin: 0;
|
8 |
+
padding: 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
|
12 |
+
/* @group Tab selector. */
|
13 |
+
.listing-metabox-tabs {
|
14 |
+
display: block;
|
15 |
+
border-bottom: solid 1px #ddd !important;
|
16 |
+
}
|
17 |
+
|
18 |
+
.listing-metabox-tabs li {
|
19 |
+
display: inline;
|
20 |
+
padding: 1px 8px;
|
21 |
+
margin: 0;
|
22 |
+
}
|
23 |
+
|
24 |
+
.listing-metabox-tabs li a {
|
25 |
+
text-decoration: none;
|
26 |
+
}
|
27 |
+
|
28 |
+
.listing-metabox-tabs li.selected {
|
29 |
+
background: #ddd;
|
30 |
+
}
|
31 |
+
|
32 |
+
.listing-metabox-tabs li.selected a {
|
33 |
+
color: #333;
|
34 |
+
}
|
35 |
+
|
36 |
+
#listing-metabox-generalinfo, #listing-metabox-fees, #listing-metabox-transactions {
|
37 |
+
display: none;
|
38 |
+
}
|
39 |
+
|
40 |
+
#listing-metabox-generalinfo > strong, #listing-metabox-fees > strong, #listing-metabox-transactions > strong {
|
41 |
+
display: block;
|
42 |
+
margin-bottom: 10px;
|
43 |
+
}
|
44 |
+
/* @end */
|
45 |
+
|
46 |
+
/* @group Categories. */
|
47 |
+
.listing-metabox-tab .listing-categories {
|
48 |
+
margin: 20px 0;
|
49 |
+
}
|
50 |
+
|
51 |
+
.listing-category {
|
52 |
+
border-bottom: dotted 1px #bbb;
|
53 |
+
}
|
54 |
+
|
55 |
+
.listing-category .header {
|
56 |
+
margin-top: 8px;
|
57 |
+
min-height: 25px;
|
58 |
+
}
|
59 |
+
|
60 |
+
.listing-category .header .spinner {
|
61 |
+
float: right;
|
62 |
+
background-size: 15px 15px;
|
63 |
+
}
|
64 |
+
|
65 |
+
.listing-category .category-name {
|
66 |
+
text-decoration: underline;
|
67 |
+
font-weight: bold;
|
68 |
+
}
|
69 |
+
|
70 |
+
.listing-category.expired .category-name {
|
71 |
+
text-decoration: line-through underline;
|
72 |
+
}
|
73 |
+
|
74 |
+
.listing-category .category-status {
|
75 |
+
float: right;
|
76 |
+
}
|
77 |
+
|
78 |
+
.listing-category .category-status.ok { background: green; }
|
79 |
+
.listing-category .category-status.pending { background: red; }
|
80 |
+
|
81 |
+
.listing-category .category-details {
|
82 |
+
margin-left: 25px;
|
83 |
+
}
|
84 |
+
|
85 |
+
.listing-category dl {
|
86 |
+
margin: 0;
|
87 |
+
clear: both;
|
88 |
+
}
|
89 |
+
|
90 |
+
.listing-category dt {
|
91 |
+
float: left;
|
92 |
+
color: #595959;
|
93 |
+
width: 80px;
|
94 |
+
}
|
95 |
+
|
96 |
+
.listing-category dd {
|
97 |
+
margin-bottom: 0;
|
98 |
+
}
|
99 |
+
|
100 |
+
.listing-category .expiration-date-info .spinner { float: left; }
|
101 |
+
|
102 |
+
.listing-category a.expiration-change-link {
|
103 |
+
float: right;
|
104 |
+
}
|
105 |
+
|
106 |
+
.listing-category .datepicker {
|
107 |
+
position: absolute;
|
108 |
+
z-index: 100;
|
109 |
+
right: 10px;
|
110 |
+
font-size: 80%;
|
111 |
+
}
|
112 |
+
|
113 |
+
.listing-category .admin-actions {
|
114 |
+
margin-top: 10px;
|
115 |
+
margin-left: 25px;
|
116 |
+
clear: both;
|
117 |
+
}
|
118 |
+
|
119 |
+
.listing-category .admin-actions li {
|
120 |
+
margin: 0;
|
121 |
+
padding: 0;
|
122 |
+
}
|
123 |
+
|
124 |
+
.listing-category .admin-actions li.delete {
|
125 |
+
margin-top: 10px;
|
126 |
+
}
|
127 |
+
|
128 |
+
.listing-category .admin-actions a.category-delete {
|
129 |
+
color: #ff0000;
|
130 |
+
}
|
131 |
+
/* @end */
|
admin/css/listing-metabox.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#BusinessDirectory_listinginfo .inside{margin:0;padding:0}.listing-metabox-tabs{display:block;border-bottom:solid 1px #ddd !important}.listing-metabox-tabs li{display:inline;padding:1px 8px;margin:0}.listing-metabox-tabs li a{text-decoration:none}.listing-metabox-tabs li.selected{background:#ddd}.listing-metabox-tabs li.selected a{color:#333}#listing-metabox-generalinfo,#listing-metabox-fees,#listing-metabox-transactions{display:none}#listing-metabox-generalinfo>strong,#listing-metabox-fees>strong,#listing-metabox-transactions>strong{display:block;margin-bottom:10px}.listing-metabox-tab .listing-categories{margin:20px 0}.listing-category{border-bottom:dotted 1px #bbb}.listing-category .header{margin-top:8px;min-height:25px}.listing-category .header .spinner{float:right;background-size:15px 15px}.listing-category .category-name{text-decoration:underline;font-weight:bold}.listing-category.expired .category-name{text-decoration:line-through underline}.listing-category .category-status{float:right}.listing-category .category-status.ok{background:green}.listing-category .category-status.pending{background:red}.listing-category .category-details{margin-left:25px}.listing-category dl{margin:0;clear:both}.listing-category dt{float:left;color:#595959;width:80px}.listing-category dd{margin-bottom:0}.listing-category .expiration-date-info .spinner{float:left}.listing-category a.expiration-change-link{float:right}.listing-category .datepicker{position:absolute;z-index:100;right:10px;font-size:80%}.listing-category .admin-actions{margin-top:10px;margin-left:25px;clear:both}.listing-category .admin-actions li{margin:0;padding:0}.listing-category .admin-actions li.delete{margin-top:10px}.listing-category .admin-actions a.category-delete{color:red}
|
admin/csv-export.php
ADDED
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CSV Export admin pages.
|
4 |
+
* @since 3.2
|
5 |
+
*/
|
6 |
+
class WPBDP_Admin_CSVExport {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
|
10 |
+
add_action( 'wp_ajax_wpbdp-csv-export', array( &$this, 'ajax_csv_export' ) );
|
11 |
+
}
|
12 |
+
|
13 |
+
public function enqueue_scripts() {
|
14 |
+
global $plugin_page;
|
15 |
+
|
16 |
+
if ( 'wpbdp-csv-export' != $plugin_page )
|
17 |
+
return;
|
18 |
+
|
19 |
+
wp_enqueue_script( 'wpbdp-admin-export-js', WPBDP_URL . 'admin/resources/export.js', array( 'wpbdp-admin-js', 'jquery-ui-dialog' ) );
|
20 |
+
wp_enqueue_style( 'wpbdp-admin-export-css', WPBDP_URL . 'admin/resources/export.css', array( 'wp-jquery-ui-dialog' ) );
|
21 |
+
}
|
22 |
+
|
23 |
+
public function dispatch() {
|
24 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/csv-export.tpl.php' );
|
25 |
+
}
|
26 |
+
|
27 |
+
public function ajax_csv_export() {
|
28 |
+
$error = '';
|
29 |
+
|
30 |
+
try {
|
31 |
+
if ( !isset( $_REQUEST['state'] ) ) {
|
32 |
+
$export = new WPBDP_CSVExporter( array_merge( $_REQUEST['settings'], array() ) );
|
33 |
+
} else {
|
34 |
+
$export = WPBDP_CSVExporter::from_state( unserialize( base64_decode( $_REQUEST['state'] ) ) );
|
35 |
+
|
36 |
+
if ( isset( $_REQUEST['cleanup'] ) && $_REQUEST['cleanup'] == 1 ) {
|
37 |
+
$export->cleanup();
|
38 |
+
} else {
|
39 |
+
$export->advance();
|
40 |
+
}
|
41 |
+
}
|
42 |
+
} catch (Exception $e) {
|
43 |
+
$error = $e->getMessage();
|
44 |
+
}
|
45 |
+
|
46 |
+
$state = ! $error ? $export->get_state() : null;
|
47 |
+
|
48 |
+
$response = array();
|
49 |
+
$response['error'] = $error;
|
50 |
+
$response['state'] = $state ? base64_encode( serialize( $state ) ) : null;
|
51 |
+
$response['count'] = $state ? count( $state['listings'] ) : 0;
|
52 |
+
$response['exported'] = $state ? $state['exported'] : 0;
|
53 |
+
$response['filesize'] = $state ? size_format( $state['filesize'] ) : 0;
|
54 |
+
$response['isDone'] = $state ? $state['done'] : false;
|
55 |
+
$response['fileurl'] = $state ? ( $state['done'] ? $export->get_file_url() : '' ) : '';
|
56 |
+
$response['filename'] = $state ? ( $state['done'] ? basename( $export->get_file_url() ) : '' ) : '';
|
57 |
+
|
58 |
+
echo json_encode( $response );
|
59 |
+
|
60 |
+
die();
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
67 |
+
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
68 |
+
|
69 |
+
/**
|
70 |
+
* CSV export.
|
71 |
+
* @since 3.2
|
72 |
+
*/
|
73 |
+
class WPBDP_CSVExporter {
|
74 |
+
|
75 |
+
const BATCH_SIZE = 20;
|
76 |
+
|
77 |
+
private $settings = array(
|
78 |
+
'csv-file-separator' => ',',
|
79 |
+
'images-separator' => ';',
|
80 |
+
'category-separator' => ';',
|
81 |
+
|
82 |
+
'test-import' => false,
|
83 |
+
'export-images' => false,
|
84 |
+
'include-users' => false,
|
85 |
+
|
86 |
+
'generate-sequence-ids' => false,
|
87 |
+
|
88 |
+
'listing_status' => 'all'
|
89 |
+
);
|
90 |
+
|
91 |
+
private $workingdir = '';
|
92 |
+
|
93 |
+
private $columns = array();
|
94 |
+
private $listings = array(); // Listing IDs to be exported.
|
95 |
+
private $exported = 0; // # of already exported listings.
|
96 |
+
private $images = array();
|
97 |
+
|
98 |
+
public function __construct( $settings, $workingdir=null, $listings=array() ) {
|
99 |
+
global $wpdb;
|
100 |
+
|
101 |
+
$this->settings = array_merge( $this->settings, $settings );
|
102 |
+
|
103 |
+
// Setup columns.
|
104 |
+
if ( $this->settings['generate-sequence-ids'] )
|
105 |
+
$this->columns['sequence_id'] = 'sequence_id';
|
106 |
+
|
107 |
+
$fields = wpbdp_get_form_fields();
|
108 |
+
foreach ( $fields as &$f ) {
|
109 |
+
$this->columns[ $f->get_short_name() ] = $f;
|
110 |
+
}
|
111 |
+
|
112 |
+
if ( $this->settings['export-images'] )
|
113 |
+
$this->columns['images'] = 'images';
|
114 |
+
|
115 |
+
if ( $this->settings['include-users'] )
|
116 |
+
$this->columns['username'] = 'username';
|
117 |
+
|
118 |
+
if ( $this->settings['include-sticky-status'] )
|
119 |
+
$this->columns['featured_level'] = 'featured_level';
|
120 |
+
|
121 |
+
if ( $this->settings['include-expiration-date'] )
|
122 |
+
$this->columns['expires_on'] = 'expires_on';
|
123 |
+
|
124 |
+
// Setup working directory.
|
125 |
+
if ( !$workingdir ) {
|
126 |
+
$direrror = '';
|
127 |
+
|
128 |
+
$upload_dir = wp_upload_dir();
|
129 |
+
|
130 |
+
if ( !$upload_dir['error'] ) {
|
131 |
+
$csvexportsdir = rtrim( $upload_dir['basedir'], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . 'wpbdp-csv-exports';
|
132 |
+
if ( is_dir( $csvexportsdir ) || mkdir( $csvexportsdir ) ) {
|
133 |
+
$this->workingdir = rtrim( $csvexportsdir . DIRECTORY_SEPARATOR . uniqid(), DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
|
134 |
+
|
135 |
+
if ( !mkdir( $this->workingdir, 0777 ) )
|
136 |
+
$direrror = _x( 'Could not create a temporary directory for handling this CSV export.', 'admin csv-export', 'WPBDM' );
|
137 |
+
} else {
|
138 |
+
$direrror = _x( 'Could not create wpbdp-csv-exports directory.', 'admin csv-export', 'WPBDM' );
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( $direrror )
|
143 |
+
throw new Exception( sprintf( _x( 'Error while creating a temporary directory for CSV export: %s', 'admin csv-export', 'WPBDM' ), $direrror ) );
|
144 |
+
} else {
|
145 |
+
$this->workingdir = $workingdir;
|
146 |
+
}
|
147 |
+
|
148 |
+
if ( $listings ) {
|
149 |
+
$this->listings = $listings;
|
150 |
+
} else {
|
151 |
+
switch ( $this->settings['listing_status'] ) {
|
152 |
+
case 'publish+draft':
|
153 |
+
$post_status = array( 'publish', 'draft', 'pending' );
|
154 |
+
break;
|
155 |
+
case 'publish':
|
156 |
+
$post_status = 'publish';
|
157 |
+
break;
|
158 |
+
case 'all':
|
159 |
+
default:
|
160 |
+
$post_status = array( 'publish', 'draft', 'pending', 'future', 'trash' );
|
161 |
+
break;
|
162 |
+
}
|
163 |
+
|
164 |
+
$this->listings = get_posts( array(
|
165 |
+
'post_status' => $post_status,
|
166 |
+
'posts_per_page' => -1,
|
167 |
+
'post_type' => WPBDP_POST_TYPE,
|
168 |
+
'fields' => 'ids'
|
169 |
+
) );
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
public static function &from_state( $state ) {
|
174 |
+
$export = new self( $state['settings'], trailingslashit( $state['workingdir'] ), (array) $state['listings'] );
|
175 |
+
$export->exported = abs( intval( $state['exported'] ) );
|
176 |
+
|
177 |
+
// Setup columns.
|
178 |
+
$shortnames = wpbdp_formfields_api()->get_short_names();
|
179 |
+
foreach ( $state['columns'] as $fshortname ) {
|
180 |
+
if ( in_array( $fshortname, array( 'images', 'username', 'featured_level', 'expires_on', 'sequence_id' ) ) ) {
|
181 |
+
$export->columns[ $fshortname ] = $fshortname;
|
182 |
+
continue;
|
183 |
+
}
|
184 |
+
|
185 |
+
$field_id = array_search( $fshortname, $shortnames );
|
186 |
+
|
187 |
+
if ( $field_id === FALSE )
|
188 |
+
throw new Exception( 'Invalid field shortname.' );
|
189 |
+
|
190 |
+
$export->columns[ $fshortname ] = wpbdp_get_form_field( $field_id );
|
191 |
+
}
|
192 |
+
|
193 |
+
return $export;
|
194 |
+
}
|
195 |
+
|
196 |
+
public function get_state() {
|
197 |
+
return array(
|
198 |
+
'settings' => $this->settings,
|
199 |
+
'columns' => array_keys( $this->columns ),
|
200 |
+
'workingdir' => $this->workingdir,
|
201 |
+
'listings' => $this->listings,
|
202 |
+
'exported' => $this->exported,
|
203 |
+
'filesize' => file_exists( $this->get_file_path() ) ? filesize( $this->get_file_path() ) : 0,
|
204 |
+
'done' => $this->is_done()
|
205 |
+
);
|
206 |
+
}
|
207 |
+
|
208 |
+
public function cleanup() {
|
209 |
+
$upload_dir = wp_upload_dir();
|
210 |
+
|
211 |
+
wpbdp_rrmdir( $this->workingdir );
|
212 |
+
|
213 |
+
if ( !$upload_dir['error'] ) {
|
214 |
+
$csvexportsdir = rtrim( $upload_dir['basedir'], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . 'wpbdp-csv-exports';
|
215 |
+
$contents = wpbdp_scandir( $csvexportsdir );
|
216 |
+
|
217 |
+
if ( !$contents )
|
218 |
+
wpbdp_rrmdir( $csvexportsdir );
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
public function advance() {
|
223 |
+
if ( $this->is_done() )
|
224 |
+
return;
|
225 |
+
|
226 |
+
define( 'PCLZIP_TEMPORARY_DIR', $this->workingdir );
|
227 |
+
require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
|
228 |
+
|
229 |
+
$csvfile = fopen( $this->workingdir . 'export.csv', 'a' );
|
230 |
+
|
231 |
+
// Write header as first line.
|
232 |
+
if ( $this->exported == 0 ) {
|
233 |
+
fwrite( $csvfile, $this->header() . "\n" );
|
234 |
+
}
|
235 |
+
|
236 |
+
$nextlistings = array_slice( $this->listings, $this->exported, self::BATCH_SIZE );
|
237 |
+
|
238 |
+
foreach ( $nextlistings as $listing_id ) {
|
239 |
+
if ( $data = $this->extract_data( $listing_id ) )
|
240 |
+
fwrite( $csvfile, implode( $this->settings['csv-file-separator'], $data ) . "\n" );
|
241 |
+
|
242 |
+
$this->exported++;
|
243 |
+
}
|
244 |
+
|
245 |
+
fclose( $csvfile );
|
246 |
+
|
247 |
+
if ( $this->is_done() ) {
|
248 |
+
if ( file_exists( $this->workingdir . 'images.zip' ) ) {
|
249 |
+
@unlink( $this->workingdir . 'export.zip' );
|
250 |
+
$zip = new PclZip( $this->workingdir . 'export.zip' );
|
251 |
+
|
252 |
+
$files = array();
|
253 |
+
$files[] = $this->workingdir . 'export.csv';
|
254 |
+
$files[] = $this->workingdir . 'images.zip';
|
255 |
+
|
256 |
+
$zip->create( implode( ',', $files ) , PCLZIP_OPT_REMOVE_ALL_PATH );
|
257 |
+
|
258 |
+
@unlink( $this->workingdir . 'export.csv' );
|
259 |
+
@unlink( $this->workingdir . 'images.zip' );
|
260 |
+
}
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
public function is_done() {
|
265 |
+
return $this->exported == count( $this->listings );
|
266 |
+
}
|
267 |
+
|
268 |
+
public function get_file_path() {
|
269 |
+
if ( file_exists( $this->workingdir . 'export.zip' ) )
|
270 |
+
return $this->workingdir . 'export.zip';
|
271 |
+
else
|
272 |
+
return $this->workingdir . 'export.csv';
|
273 |
+
}
|
274 |
+
|
275 |
+
public function get_file_url() {
|
276 |
+
$uploaddir = wp_upload_dir();
|
277 |
+
$urldir = trailingslashit( untrailingslashit( $uploaddir['baseurl'] ) . '/' . ltrim( str_replace( DIRECTORY_SEPARATOR, '/', str_replace( $uploaddir['basedir'], '', $this->workingdir ) ), '/' ) );
|
278 |
+
|
279 |
+
if ( file_exists( $this->workingdir . 'export.zip' ) )
|
280 |
+
return $urldir . 'export.zip';
|
281 |
+
else
|
282 |
+
return $urldir . 'export.csv';
|
283 |
+
|
284 |
+
return $urldir . file_exists( $this->workingdir . 'export.zip' ) ? 'export.zip' : 'export.csv';
|
285 |
+
}
|
286 |
+
|
287 |
+
private function header( $echo=false ) {
|
288 |
+
$out = '';
|
289 |
+
|
290 |
+
foreach ( $this->columns as $colname => &$col ) {
|
291 |
+
$out .= $colname;
|
292 |
+
$out .= $this->settings['csv-file-separator'];
|
293 |
+
}
|
294 |
+
|
295 |
+
$out = substr( $out, 0, -1 );
|
296 |
+
|
297 |
+
if ( $echo )
|
298 |
+
echo $out;
|
299 |
+
|
300 |
+
return $out;
|
301 |
+
}
|
302 |
+
|
303 |
+
private function extract_data( $post_id ) {
|
304 |
+
$post = get_post( $post_id );
|
305 |
+
|
306 |
+
if ( !$post || $post->post_type != WPBDP_POST_TYPE )
|
307 |
+
return false;
|
308 |
+
|
309 |
+
$listings_api = wpbdp_listings_api();
|
310 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
311 |
+
|
312 |
+
$data = array();
|
313 |
+
|
314 |
+
foreach ( $this->columns as $colname => &$col ) {
|
315 |
+
$association = is_object( $col ) ? $col->get_association() : $col;
|
316 |
+
$value = '';
|
317 |
+
|
318 |
+
switch( $association ) {
|
319 |
+
case 'sequence_id':
|
320 |
+
$value = $listings_api->calculate_sequence_id( $post->ID );
|
321 |
+
break;
|
322 |
+
|
323 |
+
/* Special columns. */
|
324 |
+
case 'images':
|
325 |
+
$upload_dir = wp_upload_dir();
|
326 |
+
$listing_images = array();
|
327 |
+
|
328 |
+
if ( $images = $listings_api->get_images( $post->ID ) ) {
|
329 |
+
foreach ( $images as &$img ) {
|
330 |
+
$img_metadata = wp_get_attachment_metadata( $img->ID );
|
331 |
+
|
332 |
+
if ( !isset( $img_metadata['file'] ) )
|
333 |
+
continue;
|
334 |
+
|
335 |
+
$img_path = realpath( $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $img_metadata['file'] );
|
336 |
+
|
337 |
+
if ( !is_readable( $img_path ) )
|
338 |
+
continue;
|
339 |
+
|
340 |
+
$this->images_archive = !isset( $this->images_archive ) ? new PclZip( $this->workingdir . 'images.zip' ) : $this->images_archive;
|
341 |
+
if ( $res = $this->images_archive->add( $img_path, PCLZIP_OPT_REMOVE_ALL_PATH ) )
|
342 |
+
$listing_images[] = basename( $img_path );
|
343 |
+
}
|
344 |
+
}
|
345 |
+
|
346 |
+
if ( $listing_images )
|
347 |
+
$value = implode( $this->settings['images-separator'], $listing_images );
|
348 |
+
|
349 |
+
break;
|
350 |
+
|
351 |
+
case 'username':
|
352 |
+
$value = get_the_author_meta( 'user_login', $post->post_author );
|
353 |
+
break;
|
354 |
+
|
355 |
+
case 'featured_level':
|
356 |
+
$listing_level = $upgrades_api->get_listing_level( $post->ID );
|
357 |
+
$value = $listing_level->id;
|
358 |
+
break;
|
359 |
+
|
360 |
+
case 'expires_on':
|
361 |
+
$terms = wp_get_post_terms( $post->ID,
|
362 |
+
WPBDP_CATEGORY_TAX,
|
363 |
+
'fields=ids' );
|
364 |
+
$expiration_dates = array();
|
365 |
+
|
366 |
+
foreach ( $terms as $term_id ) {
|
367 |
+
if ( $fee = $listings_api->get_listing_fee_for_category( $post->ID, $term_id ) ) {
|
368 |
+
$expiration_dates[] = $fee->expires_on;
|
369 |
+
} else {
|
370 |
+
$expiration_dates[] = '';
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
$value = implode( '/', $expiration_dates );
|
375 |
+
|
376 |
+
break;
|
377 |
+
|
378 |
+
/* Standard associations. */
|
379 |
+
case 'category':
|
380 |
+
case 'tags':
|
381 |
+
$terms = wp_get_post_terms( $post->ID,
|
382 |
+
$col->get_association() == 'tags' ? WPBDP_TAGS_TAX : WPBDP_CATEGORY_TAX,
|
383 |
+
'fields=names' );
|
384 |
+
if ( $terms )
|
385 |
+
$value = implode( $this->settings['category-separator'], $terms );
|
386 |
+
break;
|
387 |
+
case 'meta':
|
388 |
+
default:
|
389 |
+
$value = $col->csv_value( $post->ID );
|
390 |
+
|
391 |
+
break;
|
392 |
+
}
|
393 |
+
|
394 |
+
if ( ! is_string( $value ) )
|
395 |
+
$value = strval( $value );
|
396 |
+
|
397 |
+
$data[ $colname ] = '"' . str_replace( '"', '""', $value ) . '"';
|
398 |
+
}
|
399 |
+
|
400 |
+
return $data;
|
401 |
+
}
|
402 |
+
|
403 |
+
}
|
admin/csv-import.php
ADDED
@@ -0,0 +1,685 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CSV Import admin pages.
|
4 |
+
* @since 2.1
|
5 |
+
*/
|
6 |
+
class WPBDP_CSVImportAdmin {
|
7 |
+
|
8 |
+
public static function admin_menu_cb() {
|
9 |
+
$instance = new WPBDP_CSVImportAdmin();
|
10 |
+
$instance->dispatch();
|
11 |
+
}
|
12 |
+
|
13 |
+
public function __construct() {
|
14 |
+
$this->admin = wpbdp()->admin;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function dispatch() {
|
18 |
+
$action = wpbdp_getv($_REQUEST, 'action');
|
19 |
+
$api = wpbdp_formfields_api();
|
20 |
+
|
21 |
+
switch ($action) {
|
22 |
+
case 'example-csv':
|
23 |
+
$this->example_csv();
|
24 |
+
break;
|
25 |
+
case 'do-import':
|
26 |
+
$this->import();
|
27 |
+
break;
|
28 |
+
default:
|
29 |
+
$this->import_settings();
|
30 |
+
break;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
private function example_data_for_field( $field=null, $shortname=null ) {
|
35 |
+
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
36 |
+
|
37 |
+
if ( $field ) {
|
38 |
+
if ( $field->get_association() == 'title' ) {
|
39 |
+
return sprintf(_x('Business %s', 'admin csv-import', 'WPBDM'), $letters[rand(0,strlen($letters)-1)]);
|
40 |
+
} elseif ( $field->get_association() == 'category') {
|
41 |
+
if ( $terms = get_terms(WPBDP_CATEGORY_TAX, 'number=5&hide_empty=0') ) {
|
42 |
+
return $terms[array_rand($terms)]->name;
|
43 |
+
} else {
|
44 |
+
return '';
|
45 |
+
}
|
46 |
+
} elseif ($field->get_association() == 'tags') {
|
47 |
+
if ( $terms = get_terms(WPBDP_TAGS_TAX, 'number=5&hide_empty=0') ) {
|
48 |
+
return $terms[array_rand($terms)]->name;
|
49 |
+
} else {
|
50 |
+
return '';
|
51 |
+
}
|
52 |
+
} elseif ( $field->has_validator( 'url' ) ) {
|
53 |
+
return get_site_url();
|
54 |
+
} elseif ( $field->has_validator( 'email' ) ) {
|
55 |
+
return get_option( 'admin_email' );
|
56 |
+
} elseif ( $field->has_validator('integer_number') ) {
|
57 |
+
return rand(0, 100);
|
58 |
+
} elseif ( $field->has_validator( 'decimal_number' ) ) {
|
59 |
+
return rand(0, 100) / 100.0;
|
60 |
+
} elseif ( $field->has_validator( 'date_' ) ) {
|
61 |
+
return date( 'd/m/Y' );
|
62 |
+
} elseif ( $field->get_field_type()->get_id() == 'multiselect' || $field->get_field_type()->get_id() == 'checkbox' ) {
|
63 |
+
if ( $field->data( 'options' ) ) {
|
64 |
+
$options = $field->data( 'options' );
|
65 |
+
return $options[array_rand($options)];
|
66 |
+
}
|
67 |
+
|
68 |
+
return '';
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
if ($shortname == 'user') {
|
73 |
+
$users = get_users();
|
74 |
+
return $users[array_rand($users)]->user_login;
|
75 |
+
}
|
76 |
+
|
77 |
+
return _x('Whatever', 'admin csv-import', 'WPBDM');
|
78 |
+
}
|
79 |
+
|
80 |
+
private function example_csv() {
|
81 |
+
echo wpbdp_admin_header(_x('Example CSV Import File', 'admin csv-import', 'WPBDM'), null, array(
|
82 |
+
array(_x('← Return to "CSV Import"', 'admin csv-import', 'WPBDM'), esc_url(remove_query_arg('action')))
|
83 |
+
));
|
84 |
+
|
85 |
+
$posts = get_posts(array(
|
86 |
+
'post_type' => WPBDP_POST_TYPE,
|
87 |
+
'post_status' => 'publish',
|
88 |
+
'numberposts' => 10
|
89 |
+
));
|
90 |
+
|
91 |
+
//echo sprintf('<input type="button" value="%s" />', _x('Copy CSV', 'admin csv-import', 'WPBDM'));
|
92 |
+
echo '<textarea class="wpbdp-csv-import-example" rows="30">';
|
93 |
+
|
94 |
+
$fields_api = wpbdp_formfields_api();
|
95 |
+
|
96 |
+
$short_names = $fields_api->get_short_names();
|
97 |
+
|
98 |
+
foreach ($short_names as $name) {
|
99 |
+
echo $name . ',';
|
100 |
+
}
|
101 |
+
echo 'username';
|
102 |
+
echo "\n";
|
103 |
+
|
104 |
+
if (count($posts) >= 5) {
|
105 |
+
foreach ($posts as $post) {
|
106 |
+
foreach (array_keys($short_names) as $field_id) {
|
107 |
+
$field = $fields_api->get_field( $field_id );
|
108 |
+
$value = $field->plain_value( $post->ID );
|
109 |
+
|
110 |
+
echo str_replace( ',', ';', $value );
|
111 |
+
echo ',';
|
112 |
+
}
|
113 |
+
echo get_the_author_meta('user_login', $post->post_author);
|
114 |
+
|
115 |
+
echo "\n";
|
116 |
+
}
|
117 |
+
} else {
|
118 |
+
for ($i = 0; $i < 5; $i++) {
|
119 |
+
foreach ($short_names as $field_id => $shortname) {
|
120 |
+
$field = $fields_api->get_field( $field_id );
|
121 |
+
echo sprintf( '"%s"', $this->example_data_for_field( $field, $shortname ) );
|
122 |
+
echo ',';
|
123 |
+
}
|
124 |
+
|
125 |
+
echo sprintf( '"%s"', $this->example_data_for_field( null, 'user' ) );
|
126 |
+
echo "\n";
|
127 |
+
}
|
128 |
+
|
129 |
+
}
|
130 |
+
|
131 |
+
echo '</textarea>';
|
132 |
+
|
133 |
+
echo wpbdp_admin_footer();
|
134 |
+
}
|
135 |
+
|
136 |
+
private function import_settings() {
|
137 |
+
$tempdir = get_temp_dir();
|
138 |
+
|
139 |
+
if ( ! $tempdir || ! is_dir( $tempdir ) || ! is_writable ( $tempdir ) )
|
140 |
+
wpbdp_admin_message( sprintf( __( 'A valid temporary directory with write permissions is required for CSV imports to function properly. Your server is using "%s" but this path does not seem to be writable. Please consult with your host.',
|
141 |
+
'csv import',
|
142 |
+
'WPBDM' ),
|
143 |
+
$tempdir ),
|
144 |
+
'error' );
|
145 |
+
|
146 |
+
echo wpbdp_render_page(WPBDP_PATH . 'admin/templates/csv-import.tpl.php');
|
147 |
+
}
|
148 |
+
|
149 |
+
private function import() {
|
150 |
+
$csvfile = $_FILES['csv-file'];
|
151 |
+
$zipfile = $_FILES['images-file'];
|
152 |
+
|
153 |
+
if ($csvfile['error'] || !is_uploaded_file($csvfile['tmp_name'])) {
|
154 |
+
$this->admin->messages[] = array(_x('There was an error uploading the CSV file.', 'admin csv-import', 'WPBDM'), 'error');
|
155 |
+
return $this->import_settings();
|
156 |
+
}
|
157 |
+
|
158 |
+
if (strtolower(pathinfo($csvfile['name'], PATHINFO_EXTENSION)) != 'csv' &&
|
159 |
+
$csvfile['type'] != 'text/csv') {
|
160 |
+
$this->admin->messages[] = array(_x('The uploaded file does not look like a CSV file.', 'admin csv-import', 'WPBDM'), 'error');
|
161 |
+
return $this->import_settings();
|
162 |
+
}
|
163 |
+
|
164 |
+
$formfields_api = wpbdp_formfields_api();
|
165 |
+
$form_fields = $formfields_api->get_fields();
|
166 |
+
$shortnames = $formfields_api->get_short_names();
|
167 |
+
|
168 |
+
$fields = array();
|
169 |
+
foreach ($form_fields as $field)
|
170 |
+
$fields[$shortnames[$field->get_id()]] = $field;
|
171 |
+
|
172 |
+
$importer = new WPBDP_CSVImporter();
|
173 |
+
$importer->set_settings(array_merge($_POST['settings'], array('test-import' => isset($_POST['test-import']) ? true : false)));
|
174 |
+
$importer->set_fields($fields);
|
175 |
+
$importer->import($csvfile['tmp_name'], $zipfile['tmp_name']);
|
176 |
+
|
177 |
+
if ($importer->in_test_mode())
|
178 |
+
$this->admin->messages[] = array(_x('* Import is in test mode. Nothing was actually inserted into the database. *', 'admin csv-import', 'WPBDM'), 'error');
|
179 |
+
|
180 |
+
if ( $importer->fatal_errors ) {
|
181 |
+
foreach ( $importer->fatal_errors as $err ) {
|
182 |
+
$this->admin->messages[] = array( $err, 'error' );
|
183 |
+
}
|
184 |
+
|
185 |
+
$this->admin->messages[] = array( _x( 'Fatal errors encountered. Import will not proceed.', 'admin csv-import', 'WPBDM' ), 'error' );
|
186 |
+
}
|
187 |
+
|
188 |
+
if ($importer->rejected_rows)
|
189 |
+
$this->admin->messages[] = _x('Import was completed but some rows were rejected.', 'admin csv-import', 'WPBDM');
|
190 |
+
else
|
191 |
+
$this->admin->messages[] = _x('Import was completed successfully.', 'admin csv-import', 'WPBDM');
|
192 |
+
|
193 |
+
echo wpbdp_admin_header();
|
194 |
+
echo wpbdp_admin_notices();
|
195 |
+
|
196 |
+
echo '<h3>' . _x('Import Summary', 'admin csv-import', 'WPBDM') . '</h3>';
|
197 |
+
echo '<dl>';
|
198 |
+
echo '<dt>' . _x('Correctly imported rows:', 'admin csv-import', 'WPBDM') . '</dt>';
|
199 |
+
echo '<dd>' . count($importer->imported_rows) . '</dd>';
|
200 |
+
echo '<dt>' . _x('Rejected rows:', 'admin csv-import', 'WPBDM') . '</dt>';
|
201 |
+
echo '<dd>' . count($importer->rejected_rows) . '</dd>';
|
202 |
+
echo '</dl>';
|
203 |
+
|
204 |
+
if ($importer->rejected_rows) {
|
205 |
+
echo '<h3>' . _x('Rejected Rows', 'admin csv-import', 'WPBDM') . '</h3>';
|
206 |
+
echo '<table class="wpbdp-csv-import-results wp-list-table widefat">';
|
207 |
+
echo '<thead><tr>';
|
208 |
+
echo '<th class="line-no">' . _x('Line #', 'admin csv-import', 'WPBDM') . '</th>';
|
209 |
+
echo '<th class="line">' . _x('Line', 'admin csv-import', 'WPBDM') . '</th>';
|
210 |
+
echo '<th class="error">' . _x('Error', 'admin csv-import', 'WPBDM') . '</th>';
|
211 |
+
echo '</tr></thead>';
|
212 |
+
|
213 |
+
echo '<tbody>';
|
214 |
+
|
215 |
+
foreach ($importer->rejected_rows as $row) {
|
216 |
+
foreach ($row['errors'] as $i => $error) {
|
217 |
+
echo sprintf('<tr class="%s">', $i % 2 == 0 ? 'alternate' : '');
|
218 |
+
echo '<td class="line-no">' . $row['line'] . '</td>';
|
219 |
+
echo '<td class="line">' . substr($importer->csv[$row['line'] - 1], 0, 60) . '...</td>';
|
220 |
+
echo '<td class="error">' . $error . '</td>';
|
221 |
+
echo '</tr>';
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
echo '</tbody>';
|
226 |
+
echo '</table>';
|
227 |
+
}
|
228 |
+
|
229 |
+
if ($importer->warnings > 0) {
|
230 |
+
echo '<h3>' . _x('Import warnings (not critical)', 'admin csv-import', 'WPBDM') . '</h3>';
|
231 |
+
echo '<table class="wpbdp-csv-import-warnings wp-list-table widefat">';
|
232 |
+
echo '<thead><tr>';
|
233 |
+
echo '<th class="line-no">' . _x('Line #', 'admin csv-import', 'WPBDM') . '</th>';
|
234 |
+
echo '<th class="line">' . _x('Line', 'admin csv-import', 'WPBDM') . '</th>';
|
235 |
+
echo '<th class="error">' . _x('Warning', 'admin csv-import', 'WPBDM') . '</th>';
|
236 |
+
echo '</tr></thead>';
|
237 |
+
|
238 |
+
echo '<tbody>';
|
239 |
+
foreach ($importer->imported_rows as $row) {
|
240 |
+
if (!isset($row['warnings']))
|
241 |
+
continue;
|
242 |
+
|
243 |
+
foreach ($row['warnings'] as $i => $warning) {
|
244 |
+
echo sprintf('<tr class="%s">', $i % 2 == 0 ? 'alternate' : '');
|
245 |
+
echo '<td class="line-no">' . $row['line'] . '</td>';
|
246 |
+
echo '<td class="line">' . substr($importer->csv[$row['line'] - 1], 0, 60) . '...</td>';
|
247 |
+
echo '<td class="error">' . $warning . '</td>';
|
248 |
+
echo '</tr>';
|
249 |
+
}
|
250 |
+
|
251 |
+
}
|
252 |
+
echo '</tbody>';
|
253 |
+
echo '</table>';
|
254 |
+
}
|
255 |
+
|
256 |
+
echo wpbdp_admin_footer();
|
257 |
+
}
|
258 |
+
|
259 |
+
}
|
260 |
+
|
261 |
+
|
262 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
263 |
+
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
264 |
+
|
265 |
+
/**
|
266 |
+
* CSV import class.
|
267 |
+
* @since 2.1
|
268 |
+
*/
|
269 |
+
class WPBDP_CSVImporter {
|
270 |
+
|
271 |
+
private $settings = array(
|
272 |
+
'allow-partial-imports' => true,
|
273 |
+
|
274 |
+
'csv-file-separator' => ',',
|
275 |
+
'images-separator' => ';',
|
276 |
+
'category-separator' => ';',
|
277 |
+
'create-missing-categories' => true,
|
278 |
+
|
279 |
+
'assign-listings-to-user' => true,
|
280 |
+
'default-user' => '0',
|
281 |
+
|
282 |
+
'test-import' => false
|
283 |
+
);
|
284 |
+
|
285 |
+
private $fields = array();
|
286 |
+
private $required_fields = array();
|
287 |
+
|
288 |
+
public $csv = array();
|
289 |
+
private $header = array();
|
290 |
+
private $data = array();
|
291 |
+
|
292 |
+
private $imagesdir = null;
|
293 |
+
|
294 |
+
public $rows = array(); /* valid rows */
|
295 |
+
public $imported_rows = array();
|
296 |
+
public $rejected_rows = array();
|
297 |
+
public $warnings = 0;
|
298 |
+
public $fatal_errors = array();
|
299 |
+
|
300 |
+
|
301 |
+
public function __construct() { }
|
302 |
+
|
303 |
+
public function set_fields($fields) {
|
304 |
+
$this->fields = $fields;
|
305 |
+
|
306 |
+
foreach ( $this->fields as &$field ) {
|
307 |
+
if ( $field->is_required() )
|
308 |
+
$this->required_fields[ $field->get_short_name() ] = $field;
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
public function set_settings($settings=array()) {
|
313 |
+
$this->settings = array_merge($this->settings, $settings);
|
314 |
+
$this->settings['allow-partial-imports'] = (boolean) $this->settings['allow-partial-imports'];
|
315 |
+
$this->settings['create-missing-categories'] = (boolean) $this->settings['create-missing-categories'];
|
316 |
+
$this->settings['assign-listings-to-user'] = (boolean) $this->settings['assign-listings-to-user'];
|
317 |
+
$this->settings['default-user'] = intval($this->settings['default-user']);
|
318 |
+
}
|
319 |
+
|
320 |
+
public function in_test_mode() {
|
321 |
+
return $this->settings['test-import'] == true;
|
322 |
+
}
|
323 |
+
|
324 |
+
public function reset() {
|
325 |
+
$this->csv = array();
|
326 |
+
$this->header = array();
|
327 |
+
$this->data = array();
|
328 |
+
|
329 |
+
$this->rows = array();
|
330 |
+
$this->imported_rows = array();
|
331 |
+
$this->rejected_rows = array();
|
332 |
+
$this->warnings = 0;
|
333 |
+
|
334 |
+
$this->imagesdir = null;
|
335 |
+
}
|
336 |
+
|
337 |
+
public function import($csv_file, $zipfile) {
|
338 |
+
$this->reset();
|
339 |
+
$this->extract_data($csv_file);
|
340 |
+
$this->extract_images($zipfile);
|
341 |
+
|
342 |
+
foreach ($this->rows as $row) {
|
343 |
+
if ($this->import_row($row['data'], $errors, $warnings)) {
|
344 |
+
if ($warnings) {
|
345 |
+
$this->warnings += count($warnings);
|
346 |
+
$row['warnings'] = $warnings;
|
347 |
+
}
|
348 |
+
|
349 |
+
$this->imported_rows[] = $row;
|
350 |
+
} else {
|
351 |
+
$row['errors'] = $errors;
|
352 |
+
$this->rejected_rows[] = $row;
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
// delete $imagesdir
|
357 |
+
if ($this->imagesdir)
|
358 |
+
$this->remove_directory($this->imagesdir);
|
359 |
+
}
|
360 |
+
|
361 |
+
private function process_line($row) {
|
362 |
+
if (count($row) > count($this->header)) {
|
363 |
+
return false; // row has more columns than the header
|
364 |
+
}
|
365 |
+
|
366 |
+
if (count($row) < count($this->header)) {
|
367 |
+
$row = array_merge($row, array_fill(0, count($this->header) - count($row), null));
|
368 |
+
}
|
369 |
+
|
370 |
+
return $row;
|
371 |
+
}
|
372 |
+
|
373 |
+
private function extract_data($csv_file) {
|
374 |
+
ini_set('auto_detect_line_endings', true);
|
375 |
+
|
376 |
+
$fp = fopen($csv_file, 'r');
|
377 |
+
|
378 |
+
$n = 0;
|
379 |
+
while (($line_data = fgetcsv($fp, 0, $this->settings['csv-file-separator'])) !== FALSE) {
|
380 |
+
$this->csv[] = implode( $this->settings['csv-file-separator'], $line_data );
|
381 |
+
|
382 |
+
if ($line_data) {
|
383 |
+
if (!$this->header) {
|
384 |
+
$this->header = $line_data;
|
385 |
+
|
386 |
+
foreach ($this->header as &$h) $h = trim($h);
|
387 |
+
|
388 |
+
foreach ( $this->required_fields as $shortname => $field ) {
|
389 |
+
if ( !in_array( $shortname, $this->header ) ) {
|
390 |
+
$this->fatal_errors[] = sprintf( _x( 'Missing required header column: %s', 'admin csv-import', 'WPBDM' ), $shortname );
|
391 |
+
}
|
392 |
+
}
|
393 |
+
|
394 |
+
if ( $this->fatal_errors ) {
|
395 |
+
@fclose( $fp );
|
396 |
+
return false;
|
397 |
+
}
|
398 |
+
|
399 |
+
} else {
|
400 |
+
if ($row = $this->process_line($line_data)) {
|
401 |
+
$this->rows[] = array('line' => $n + 1, 'data' => $row, 'error' => false);
|
402 |
+
} else {
|
403 |
+
$this->rejected_rows[] = array('line' => $n + 1, 'data' => $row, 'errors' => array(_x('Malformed row (too many columns)', 'admin csv-import', 'WPBDM')) );
|
404 |
+
}
|
405 |
+
}
|
406 |
+
}
|
407 |
+
|
408 |
+
$n++;
|
409 |
+
}
|
410 |
+
|
411 |
+
@fclose($fp);
|
412 |
+
|
413 |
+
}
|
414 |
+
|
415 |
+
private function extract_images($zipfile) {
|
416 |
+
$dir = trailingslashit(trailingslashit(get_temp_dir()) . 'wpbdp_' . time());
|
417 |
+
|
418 |
+
require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
|
419 |
+
|
420 |
+
$zip = new PclZip($zipfile);
|
421 |
+
if ($files = $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_REMOVE_ALL_PATH)) {
|
422 |
+
$this->imagesdir = $dir;
|
423 |
+
return true;
|
424 |
+
}
|
425 |
+
|
426 |
+
return false;
|
427 |
+
}
|
428 |
+
|
429 |
+
private function import_row($data, &$errors=null, &$warnings=null) {
|
430 |
+
global $wpdb;
|
431 |
+
|
432 |
+
$errors = array();
|
433 |
+
$warnings = array();
|
434 |
+
|
435 |
+
$listing_username = null;
|
436 |
+
|
437 |
+
$state = new StdClass();
|
438 |
+
$state->categories = array();
|
439 |
+
$state->fields = array();
|
440 |
+
$state->images = array();
|
441 |
+
|
442 |
+
$listing_images = array();
|
443 |
+
$listing_fields = array();
|
444 |
+
$listing_metadata = array( 'featured_level' => '', 'expires_on' => array() );
|
445 |
+
|
446 |
+
|
447 |
+
foreach ($this->header as $i => $header_name) {
|
448 |
+
if ( ($header_name == 'image' || $header_name == 'images') ) {
|
449 |
+
if ( !empty($data[$i]) ) {
|
450 |
+
if (strpos($data[$i], $this->settings['images-separator']) !== false) {
|
451 |
+
foreach (explode($this->settings['images-separator'], $data[$i]) as $image) {
|
452 |
+
$listing_images[] = trim($image);
|
453 |
+
}
|
454 |
+
} else {
|
455 |
+
$listing_images[] = trim($data[$i]);
|
456 |
+
}
|
457 |
+
}
|
458 |
+
|
459 |
+
continue;
|
460 |
+
}
|
461 |
+
|
462 |
+
if ($header_name == 'username') {
|
463 |
+
$listing_username = $data[$i];
|
464 |
+
|
465 |
+
if ( $listing_username ) {
|
466 |
+
if ( !username_exists( $listing_username ) ) {
|
467 |
+
$errors[] = sprintf( _x( 'Username "%s" does not exist', 'admin csv-import', 'WPBDM' ), $listing_username );
|
468 |
+
return false;
|
469 |
+
}
|
470 |
+
}
|
471 |
+
continue;
|
472 |
+
}
|
473 |
+
|
474 |
+
if ( $header_name == 'featured_level' ) {
|
475 |
+
$listing_metadata['featured_level'] = $data[ $i ];
|
476 |
+
continue;
|
477 |
+
}
|
478 |
+
|
479 |
+
if ( $header_name == 'expires_on' ) {
|
480 |
+
$listing_metadata['expires_on'] = explode( '/', $data[ $i ] );
|
481 |
+
continue;
|
482 |
+
}
|
483 |
+
|
484 |
+
if ( 'sequence_id' == $header_name ) {
|
485 |
+
$listing_metadata['sequence_id'] = $data[ $i ];
|
486 |
+
continue;
|
487 |
+
}
|
488 |
+
|
489 |
+
if (!array_key_exists($header_name, $this->fields)) {
|
490 |
+
$warnings[] = sprintf(_x('Ignoring unknown field "%s"', 'admin csv-import', 'WPBDM'), $header_name);
|
491 |
+
continue;
|
492 |
+
}
|
493 |
+
|
494 |
+
$field = $this->fields[$header_name];
|
495 |
+
|
496 |
+
if ( $field->is_required() && $field->is_empty_value( $data[$i] ) ) {
|
497 |
+
$errors[] = sprintf( _x( 'Missing required field: %s', 'admin csv-import', 'WPBDM' ), $header_name );
|
498 |
+
return false;
|
499 |
+
}
|
500 |
+
|
501 |
+
if ($field->get_association() == 'category') {
|
502 |
+
$categories = array_map('trim', explode($this->settings['category-separator'], $data[$i]));
|
503 |
+
|
504 |
+
foreach ($categories as $category_name) {
|
505 |
+
$category_name = strip_tags(str_replace("\n", "-", $category_name));
|
506 |
+
$category_name = str_replace( array( '"', "'" ), '', $category_name );
|
507 |
+
|
508 |
+
// Workaround for WP #30419.
|
509 |
+
if ( false !== strpos( $category_name, '&' ) ) {
|
510 |
+
$category_name = str_replace( '&', '&', $category_name );
|
511 |
+
}
|
512 |
+
|
513 |
+
if (!$category_name)
|
514 |
+
continue;
|
515 |
+
|
516 |
+
if ($term = term_exists($category_name, WPBDP_CATEGORY_TAX)) {
|
517 |
+
$state->categories[] = $term['term_id'];
|
518 |
+
// $listing_fields[$field->get_id()][] = $term['term_id'];
|
519 |
+
} else {
|
520 |
+
if ($this->settings['create-missing-categories']) {
|
521 |
+
if ($this->in_test_mode())
|
522 |
+
continue;
|
523 |
+
|
524 |
+
$category_name = str_replace( '&', '&', $category_name );
|
525 |
+
|
526 |
+
if ($newterm = wp_insert_term($category_name, WPBDP_CATEGORY_TAX)) {
|
527 |
+
$state->categories[] = $newterm['term_id'];
|
528 |
+
} else {
|
529 |
+
$errors[] = sprintf(_x('Could not create listing category "%s"', 'admin csv-import', 'WPBDM'), $category_name);
|
530 |
+
return false;
|
531 |
+
}
|
532 |
+
|
533 |
+
} else {
|
534 |
+
$errors[] = sprintf(_x('Listing category "%s" does not exist', 'admin csv-import', 'WPBDM'), $category_name);
|
535 |
+
return false;
|
536 |
+
}
|
537 |
+
}
|
538 |
+
}
|
539 |
+
} elseif ($field->get_association() == 'tags') {
|
540 |
+
$tags = stripslashes( $data[ $i ] );
|
541 |
+
$tags = array_map( 'trim', explode( $this->settings['category-separator'], $tags ) );
|
542 |
+
// $tags = $field->get_field_type()->get_id() == 'textfield' ? implode( ',', $tags ) : $tags;
|
543 |
+
// $tags = $field->convert_input( $tags );
|
544 |
+
$listing_fields[$field->get_id()] = $tags;
|
545 |
+
} else {
|
546 |
+
$listing_fields[$field->get_id()] = $field->convert_csv_input( $data[$i] );
|
547 |
+
}
|
548 |
+
}
|
549 |
+
|
550 |
+
if ($listing_images) {
|
551 |
+
if (!$this->imagesdir) {
|
552 |
+
$errors[] = _x('Images were specified but no image file was uploaded.', 'admin csv-import', 'WPBDM');
|
553 |
+
return false;
|
554 |
+
}
|
555 |
+
|
556 |
+
foreach ($listing_images as $filename) {
|
557 |
+
if (file_exists($this->imagesdir . $filename)) {
|
558 |
+
$filepath = $this->imagesdir . $filename;
|
559 |
+
|
560 |
+
$file = array('name' => basename($filepath),
|
561 |
+
'tmp_name' => $filepath,
|
562 |
+
'error' => 0,
|
563 |
+
'size' => filesize($filepath)
|
564 |
+
);
|
565 |
+
|
566 |
+
copy($filepath, $filepath . '.backup'); // make a file backup becase wp_handle_sideload() moves the original file and it may be needed for other listings
|
567 |
+
$wp_image = wp_handle_sideload($file, array('test_form' => FALSE));
|
568 |
+
rename($filepath . '.backup', $filepath);
|
569 |
+
|
570 |
+
if (!isset($wp_image['error'])) {
|
571 |
+
if ($attachment_id = wp_insert_attachment(array(
|
572 |
+
'post_mime_type' => $wp_image['type'],
|
573 |
+
'post_title' => preg_replace('/\.[^.]+$/', '', basename($wp_image['file'])),
|
574 |
+
'post_content' => '',
|
575 |
+
'post_status' => 'inherit'
|
576 |
+
), $wp_image['file'])) {
|
577 |
+
|
578 |
+
$attach_data = wp_generate_attachment_metadata($attachment_id, $wp_image['file']);
|
579 |
+
wp_update_attachment_metadata($attachment_id, $attach_data);
|
580 |
+
|
581 |
+
$state->images[] = $attachment_id;
|
582 |
+
|
583 |
+
} else {
|
584 |
+
$errors[] = sprintf(_x('Image file "%s" could not be inserted.', 'admin csv-import', 'WPBDM'), $filename);
|
585 |
+
return false;
|
586 |
+
}
|
587 |
+
} else {
|
588 |
+
$errors[] = sprintf(_x('Image file "%s" could not be uploaded.', 'admin csv-import', 'WPBDM'), $filename);
|
589 |
+
return false;
|
590 |
+
}
|
591 |
+
} else {
|
592 |
+
$errors[] = sprintf(_x('Referenced image file "%s" was not found inside ZIP file.', 'admin csv-import'. 'WPBDM'), $filename);
|
593 |
+
return false;
|
594 |
+
}
|
595 |
+
}
|
596 |
+
}
|
597 |
+
|
598 |
+
$state->fields = $listing_fields;
|
599 |
+
|
600 |
+
if ($this->settings['test-import'])
|
601 |
+
return true;
|
602 |
+
|
603 |
+
$listing = false;
|
604 |
+
if ( isset( $listing_metadata['sequence_id'] ) && $listing_metadata['sequence_id'] ) {
|
605 |
+
$post_id = intval( $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1",
|
606 |
+
'_wpbdp[import_sequence_id]', $listing_metadata['sequence_id'] ) ) );
|
607 |
+
if ( $post_id && false !== get_post_status( $post_id ) )
|
608 |
+
$listing = WPBDP_Listing::get( $post_id );
|
609 |
+
}
|
610 |
+
|
611 |
+
if ( ! $listing ) {
|
612 |
+
$listing = WPBDP_Listing::create( $state );
|
613 |
+
$listing->set_field_values( $state->fields );
|
614 |
+
$listing->set_images( $state->images );
|
615 |
+
$listing->set_categories( $state->categories );
|
616 |
+
$listing->set_post_status( wpbdp_get_option( 'new-post-status' ) );
|
617 |
+
$listing->save();
|
618 |
+
} else {
|
619 |
+
$listing->update( $state );
|
620 |
+
$listing->set_post_status( wpbdp_get_option( 'edit-post-status' ) );
|
621 |
+
}
|
622 |
+
|
623 |
+
// create permalink
|
624 |
+
$post = get_post($listing->get_id());
|
625 |
+
wp_update_post(array('ID' => $post->ID,
|
626 |
+
'post_name' => wp_unique_post_slug(sanitize_title($post->post_title), $post->ID, $post->post_status, $post->post_type, $post->post_parent)
|
627 |
+
));
|
628 |
+
|
629 |
+
|
630 |
+
if ($this->settings['assign-listings-to-user']) {
|
631 |
+
if ($listing_username) {
|
632 |
+
if ($user = get_user_by('login', $listing_username))
|
633 |
+
wp_update_post(array('ID' => $listing->get_id(), 'post_author' => $user->ID));
|
634 |
+
} else {
|
635 |
+
if ($this->settings['default-user'])
|
636 |
+
wp_update_post(array('ID' => $listing->get_id(), 'post_author' => $this->settings['default-user']));
|
637 |
+
}
|
638 |
+
}
|
639 |
+
|
640 |
+
// Handle listing additional metadata.
|
641 |
+
if ( $listing_metadata['featured_level'] ) {
|
642 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
643 |
+
|
644 |
+
if ( $level = $upgrades_api->get( $listing_metadata['featured_level'] ) ) {
|
645 |
+
$upgrades_api->set_sticky( $listing->get_id(), $level->id );
|
646 |
+
}
|
647 |
+
}
|
648 |
+
|
649 |
+
if ( $listing_metadata['expires_on'] ) {
|
650 |
+
foreach ( $state->categories as $i => $category_id ) {
|
651 |
+
if ( isset( $listing_metadata['expires_on'][ $i ] ) && ! empty( $listing_metadata['expires_on'][ $i ] ) ) { // TODO: check is valid date
|
652 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_listing_fees',
|
653 |
+
array( 'expires_on' => $listing_metadata['expires_on'][ $i ] ),
|
654 |
+
array( 'category_id' => $category_id, 'listing_id' => $listing->get_id() )
|
655 |
+
);
|
656 |
+
}
|
657 |
+
}
|
658 |
+
}
|
659 |
+
|
660 |
+
if ( isset( $listing_metadata['sequence_id'] ) && $listing_metadata['sequence_id'] )
|
661 |
+
update_post_meta( $listing->get_id(), '_wpbdp[import_sequence_id]', $listing_metadata['sequence_id'] );
|
662 |
+
|
663 |
+
set_time_limit(5);
|
664 |
+
|
665 |
+
return true;
|
666 |
+
}
|
667 |
+
|
668 |
+
private function remove_directory($dir) {
|
669 |
+
foreach (scandir($dir) as $file) {
|
670 |
+
if ($file == '.' || $file == '..') continue;
|
671 |
+
|
672 |
+
if (is_dir($dir . $file)) {
|
673 |
+
$this->remove_directory($dir . $file);
|
674 |
+
rmdir($dir. $file);
|
675 |
+
} else {
|
676 |
+
unlink($dir . $file);
|
677 |
+
}
|
678 |
+
}
|
679 |
+
|
680 |
+
rmdir($dir);
|
681 |
+
|
682 |
+
$this->imagesdir = null;
|
683 |
+
}
|
684 |
+
|
685 |
+
}
|
admin/fees.php
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!class_exists('WP_List_Table'))
|
3 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
4 |
+
|
5 |
+
class WPBDP_FeesTable extends WP_List_Table {
|
6 |
+
|
7 |
+
public function __construct() {
|
8 |
+
parent::__construct(array(
|
9 |
+
'singular' => _x('fee', 'fees admin', 'WPBDM'),
|
10 |
+
'plural' => _x('fees', 'fees admin', 'WPBDM'),
|
11 |
+
'ajax' => false
|
12 |
+
));
|
13 |
+
}
|
14 |
+
|
15 |
+
public function no_items() {
|
16 |
+
echo _x('You do not have any listing fees setup yet.', 'fees admin', 'WPBDM');
|
17 |
+
}
|
18 |
+
|
19 |
+
public function get_columns() {
|
20 |
+
return array(
|
21 |
+
/* 'order' => _x( 'Order', 'fees admin', 'WPBDM' ),*/
|
22 |
+
'label' => _x('Label', 'fees admin', 'WPBDM'),
|
23 |
+
'amount' => _x('Amount', 'fees admin', 'WPBDM'),
|
24 |
+
'duration' => _x('Duration', 'fees admin', 'WPBDM'),
|
25 |
+
'images' => _x('Images', 'fees admin', 'WPBDM'),
|
26 |
+
'categories' => _x('Applied To', 'fees admin', 'WPBDM')
|
27 |
+
);
|
28 |
+
}
|
29 |
+
|
30 |
+
public function prepare_items() {
|
31 |
+
$this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
|
32 |
+
|
33 |
+
$api = wpbdp_fees_api();
|
34 |
+
$this->items = $api->get_fees();
|
35 |
+
}
|
36 |
+
|
37 |
+
/* Rows */
|
38 |
+
public function column_order( $fee ) {
|
39 |
+
return sprintf( '<span class="wpbdp-drag-handle" data-fee-id="%s"></span> <a href="%s"><strong>↑</strong></a> | <a href="%s"><strong>↓</strong></a>',
|
40 |
+
$fee->id,
|
41 |
+
esc_url( add_query_arg( array('action' => 'feeup', 'id' => $fee->id ) ) ),
|
42 |
+
esc_url( add_query_arg( array('action' => 'feedown', 'id' => $fee->id ) ) )
|
43 |
+
);
|
44 |
+
}
|
45 |
+
|
46 |
+
public function column_label($fee) {
|
47 |
+
$actions = array();
|
48 |
+
$actions['edit'] = sprintf('<a href="%s">%s</a>',
|
49 |
+
esc_url(add_query_arg(array('action' => 'editfee', 'id' => $fee->id))),
|
50 |
+
_x('Edit', 'fees admin', 'WPBDM'));
|
51 |
+
$actions['delete'] = sprintf('<a href="%s">%s</a>',
|
52 |
+
esc_url(add_query_arg(array('action' => 'deletefee', 'id' => $fee->id))),
|
53 |
+
_x('Delete', 'fees admin', 'WPBDM'));
|
54 |
+
|
55 |
+
$html = '';
|
56 |
+
$html .= sprintf( '<span class="wpbdp-drag-handle" data-fee-id="%s"></span></a>',
|
57 |
+
$fee->id );
|
58 |
+
|
59 |
+
$html .= sprintf('<strong><a href="%s">%s</a></strong>',
|
60 |
+
esc_url(add_query_arg(array('action' => 'editfee', 'id' => $fee->id))),
|
61 |
+
esc_attr($fee->label));
|
62 |
+
$html .= $this->row_actions($actions);
|
63 |
+
|
64 |
+
return $html;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function column_amount($fee) {
|
68 |
+
return $fee->amount;
|
69 |
+
}
|
70 |
+
|
71 |
+
public function column_duration($fee) {
|
72 |
+
if ($fee->days == 0)
|
73 |
+
return _x('Forever', 'fees admin', 'WPBDM');
|
74 |
+
return sprintf(_nx('%d day', '%d days', $fee->days, 'fees admin', 'WPBDM'), $fee->days);
|
75 |
+
}
|
76 |
+
|
77 |
+
public function column_images($fee) {
|
78 |
+
return sprintf(_nx('%d image', '%d images', $fee->images, 'fees admin', 'WPBDM'), $fee->images);
|
79 |
+
}
|
80 |
+
|
81 |
+
public function column_categories($fee) {
|
82 |
+
if ($fee->categories['all'])
|
83 |
+
return _x('All categories', 'fees admin', 'WPBDM');
|
84 |
+
|
85 |
+
$names = array();
|
86 |
+
|
87 |
+
foreach ($fee->categories['categories'] as $category_id) {
|
88 |
+
if ($category = get_term($category_id, wpbdp()->get_post_type_category())) {
|
89 |
+
$names[] = $category->name;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
return $names ? join($names, ', ') : '--';
|
94 |
+
}
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
|
99 |
+
class WPBDP_FeesAdmin {
|
100 |
+
|
101 |
+
public function __construct() {
|
102 |
+
$this->admin = wpbdp()->admin;
|
103 |
+
$this->api = wpbdp()->fees;
|
104 |
+
}
|
105 |
+
|
106 |
+
public function dispatch() {
|
107 |
+
$action = wpbdp_getv($_REQUEST, 'action');
|
108 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg(array('action', 'id'), $_SERVER['REQUEST_URI']);
|
109 |
+
|
110 |
+
switch ($action) {
|
111 |
+
case 'addfee':
|
112 |
+
case 'editfee':
|
113 |
+
$this->processFieldForm();
|
114 |
+
break;
|
115 |
+
case 'deletefee':
|
116 |
+
$this->delete_fee();
|
117 |
+
break;
|
118 |
+
default:
|
119 |
+
$this->feesTable();
|
120 |
+
break;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
public static function admin_menu_cb() {
|
125 |
+
$instance = new WPBDP_FeesAdmin();
|
126 |
+
$instance->dispatch();
|
127 |
+
}
|
128 |
+
|
129 |
+
/* field list */
|
130 |
+
private function feesTable() {
|
131 |
+
$table = new WPBDP_FeesTable();
|
132 |
+
$table->prepare_items();
|
133 |
+
|
134 |
+
$order_options = array();
|
135 |
+
foreach ( array( 'label' => _x( 'Label', 'fees order', 'WPBDM' ),
|
136 |
+
'amount' => _x( 'Amount', 'fees order', 'WPBDM' ),
|
137 |
+
'days' => _x( 'Duration', 'fees order', 'WPBDM' ),
|
138 |
+
'images' => _x( 'Images', 'fees order', 'WPBDM' ),
|
139 |
+
'custom' => _x( 'Custom Order', 'fees order', 'WPBDM' ) ) as $k => $l ) {
|
140 |
+
$order_options[ $k ] = $l;
|
141 |
+
}
|
142 |
+
|
143 |
+
wpbdp_render_page(WPBDP_PATH . 'admin/templates/fees.tpl.php',
|
144 |
+
array( 'table' => $table,
|
145 |
+
'order_options' => $order_options,
|
146 |
+
'current_order' => wpbdp_get_option( 'fee-order' ) ),
|
147 |
+
true);
|
148 |
+
}
|
149 |
+
|
150 |
+
private function processFieldForm() {
|
151 |
+
if (isset($_POST['fee'])) {
|
152 |
+
if ($this->api->add_or_update_fee($_POST['fee'], $errors)) {
|
153 |
+
$this->admin->messages[] = _x('Fee updated.', 'fees admin', 'WPBDM');
|
154 |
+
return $this->feesTable();
|
155 |
+
} else {
|
156 |
+
$errmsg = '';
|
157 |
+
foreach ($errors as $err)
|
158 |
+
$errmsg .= sprintf('• %s<br />', $err);
|
159 |
+
|
160 |
+
$this->admin->messages[] = array($errmsg, 'error');
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
$fee = isset($_GET['id']) ? $this->api->get_fee_by_id($_GET['id']) : null;
|
165 |
+
|
166 |
+
wpbdp_render_page(WPBDP_PATH . 'admin/templates/fees-addoredit.tpl.php',
|
167 |
+
array(
|
168 |
+
'fee' => $fee,
|
169 |
+
'fee_extra_settings' => wpbdp_capture_action_array( 'wpbdp_admin_fee_form_extra_settings', array( &$fee ) )
|
170 |
+
),
|
171 |
+
true);
|
172 |
+
}
|
173 |
+
|
174 |
+
private function delete_fee() {
|
175 |
+
global $wpdb;
|
176 |
+
|
177 |
+
if (isset($_POST['doit'])) {
|
178 |
+
$this->api->delete_fee($_POST['id']);
|
179 |
+
$this->admin->messages[] = _x('Fee deleted.', 'fees admin', 'WPBDM');
|
180 |
+
|
181 |
+
return $this->feesTable();
|
182 |
+
} else {
|
183 |
+
if ($fee = $this->api->get_fee_by_id($_REQUEST['id'])) {
|
184 |
+
wpbdp_render_page(WPBDP_PATH . 'admin/templates/fees-confirm-delete.tpl.php',
|
185 |
+
array('fee' => $fee),
|
186 |
+
true);
|
187 |
+
}
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
}
|
admin/form-fields.php
ADDED
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!class_exists('WP_List_Table'))
|
3 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
4 |
+
|
5 |
+
class WPBDP_FormFieldsTable extends WP_List_Table {
|
6 |
+
|
7 |
+
public function __construct() {
|
8 |
+
parent::__construct(array(
|
9 |
+
'singular' => _x('form field', 'form-fields admin', 'WPBDM'),
|
10 |
+
'plural' => _x('form fields', 'form-fields admin', 'WPBDM'),
|
11 |
+
'ajax' => false
|
12 |
+
));
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get_columns() {
|
16 |
+
return array(
|
17 |
+
'order' => _x('Order', 'form-fields admin', 'WPBDM'),
|
18 |
+
'label' => _x('Label / Association', 'form-fields admin', 'WPBDM'),
|
19 |
+
'type' => _x('Type', 'form-fields admin', 'WPBDM'),
|
20 |
+
'validator' => _x('Validator', 'form-fields admin', 'WPBDM'),
|
21 |
+
'tags' => _x( 'Field Attributes', 'form-fields admin', 'WPBDM' ),
|
22 |
+
);
|
23 |
+
}
|
24 |
+
|
25 |
+
public function prepare_items() {
|
26 |
+
$this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
|
27 |
+
|
28 |
+
$formfields_api = WPBDP_FormFields::instance();
|
29 |
+
$this->items = $formfields_api->get_fields();
|
30 |
+
}
|
31 |
+
|
32 |
+
/* Rows */
|
33 |
+
public function column_order($field) {
|
34 |
+
return sprintf( '<span class="wpbdp-drag-handle" data-field-id="%s"></span> <a href="%s"><strong>↑</strong></a> | <a href="%s"><strong>↓</strong></a>',
|
35 |
+
$field->get_id(),
|
36 |
+
esc_url( add_query_arg( array('action' => 'fieldup', 'id' => $field->get_id() ) ) ) ,
|
37 |
+
esc_url( add_query_arg( array('action' => 'fielddown', 'id' => $field->get_id() ) ) )
|
38 |
+
);
|
39 |
+
}
|
40 |
+
|
41 |
+
public function column_label( $field ) {
|
42 |
+
$actions = array();
|
43 |
+
$actions['edit'] = sprintf( '<a href="%s">%s</a>',
|
44 |
+
esc_url( add_query_arg( array( 'action' => 'editfield', 'id' => $field->get_id() ) ) ),
|
45 |
+
_x( 'Edit', 'form-fields admin', 'WPBDM' ) );
|
46 |
+
|
47 |
+
if ( ! $field->has_behavior_flag( 'no-delete' ) ) {
|
48 |
+
$actions['delete'] = sprintf( '<a href="%s">%s</a>',
|
49 |
+
esc_url( add_query_arg( array( 'action' => 'deletefield', 'id' => $field->get_id() ) ) ),
|
50 |
+
_x( 'Delete', 'form-fields admin', 'WPBDM') );
|
51 |
+
}
|
52 |
+
|
53 |
+
$html = '';
|
54 |
+
$html .= sprintf( '<strong><a href="%s">%s</a></strong> (as <i>%s</i>)',
|
55 |
+
esc_url( add_query_arg( array( 'action' => 'editfield', 'id' => $field->get_id() ) ) ),
|
56 |
+
esc_attr( $field->get_label() ),
|
57 |
+
$field->get_association() );
|
58 |
+
$html .= $this->row_actions( $actions );
|
59 |
+
|
60 |
+
return $html;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function column_type( $field ) {
|
64 |
+
return esc_html( $field->get_field_type()->get_name() );
|
65 |
+
}
|
66 |
+
|
67 |
+
public function column_validator( $field ) {
|
68 |
+
return esc_html( implode( ',', $field->get_validators() ) );
|
69 |
+
}
|
70 |
+
|
71 |
+
public function column_tags( $field ) {
|
72 |
+
$html = '';
|
73 |
+
|
74 |
+
$html .= sprintf( '<span class="tag %s">%s</span>',
|
75 |
+
$field->is_required() ? 'required' : 'optional',
|
76 |
+
$field->is_required() ? _x( 'Required', 'form-fields admin', 'WPBDM' ) : _x( 'Optional', 'form-fields admin', 'WPBDM' ) );
|
77 |
+
|
78 |
+
if ( $field->display_in( 'excerpt' ) ) {
|
79 |
+
$html .= sprintf( '<span class="tag in-excerpt" title="%s">%s</span>',
|
80 |
+
_x( 'This field value is shown in the excerpt view of a listing.', 'form-fields admin', 'WPBDM' ),
|
81 |
+
_x( 'In Excerpt', 'form-fields admin', 'WPBDM' ) );
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( $field->display_in( 'listing' ) ) {
|
85 |
+
$html .= sprintf( '<span class="tag in-listing" title="%s">%s</span>',
|
86 |
+
_x( 'This field value is shown in the single view of a listing.', 'form-fields admin', 'WPBDM' ),
|
87 |
+
_x( 'In Listing', 'form-fields admin', 'WPBDM' ) );
|
88 |
+
}
|
89 |
+
|
90 |
+
return $html;
|
91 |
+
}
|
92 |
+
|
93 |
+
}
|
94 |
+
|
95 |
+
class WPBDP_FormFieldsAdmin {
|
96 |
+
|
97 |
+
public function __construct() {
|
98 |
+
$this->api = wpbdp_formfields_api();
|
99 |
+
$this->admin = wpbdp()->admin;
|
100 |
+
}
|
101 |
+
|
102 |
+
public function dispatch() {
|
103 |
+
$action = wpbdp_getv($_REQUEST, 'action');
|
104 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg(array('action', 'id'), $_SERVER['REQUEST_URI']);
|
105 |
+
|
106 |
+
switch ($action) {
|
107 |
+
case 'addfield':
|
108 |
+
case 'editfield':
|
109 |
+
$this->processFieldForm();
|
110 |
+
break;
|
111 |
+
case 'deletefield':
|
112 |
+
$this->deleteField();
|
113 |
+
break;
|
114 |
+
case 'fieldup':
|
115 |
+
case 'fielddown':
|
116 |
+
if ( $field = $this->api->get_field( $_REQUEST['id'] ) ) {
|
117 |
+
$field->reorder( $action == 'fieldup' ? 1 : -1 );
|
118 |
+
}
|
119 |
+
$this->fieldsTable();
|
120 |
+
break;
|
121 |
+
case 'previewform':
|
122 |
+
$this->previewForm();
|
123 |
+
break;
|
124 |
+
case 'createrequired':
|
125 |
+
$this->createRequiredFields();
|
126 |
+
break;
|
127 |
+
default:
|
128 |
+
$this->fieldsTable();
|
129 |
+
break;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
public static function admin_menu_cb() {
|
134 |
+
$instance = new WPBDP_FormFieldsAdmin();
|
135 |
+
$instance->dispatch();
|
136 |
+
}
|
137 |
+
|
138 |
+
public static function _render_field_settings() {
|
139 |
+
$api = wpbdp_formfields_api();
|
140 |
+
|
141 |
+
$association = wpbdp_getv( $_REQUEST, 'association', false );
|
142 |
+
$field_type = $api->get_field_type( wpbdp_getv( $_REQUEST, 'field_type', false ) );
|
143 |
+
$field_id = wpbdp_getv( $_REQUEST, 'field_id', 0 );
|
144 |
+
|
145 |
+
$response = array( 'ok' => false, 'html' => '' );
|
146 |
+
|
147 |
+
if ( $field_type && in_array( $association, $field_type->get_supported_associations(), true ) ) {
|
148 |
+
$field = $api->get_field( $field_id );
|
149 |
+
|
150 |
+
$field_settings = '';
|
151 |
+
$field_settings .= $field_type->render_field_settings( $field, $association );
|
152 |
+
|
153 |
+
ob_start();
|
154 |
+
do_action_ref_array( 'wpbdp_form_field_settings', array( &$field, $association ) );
|
155 |
+
$field_settings .= ob_get_contents();
|
156 |
+
ob_end_clean();
|
157 |
+
|
158 |
+
$response['ok'] = true;
|
159 |
+
$response['html'] = $field_settings;
|
160 |
+
}
|
161 |
+
|
162 |
+
echo json_encode( $response );
|
163 |
+
exit;
|
164 |
+
}
|
165 |
+
|
166 |
+
/* preview form */
|
167 |
+
private function previewForm() {
|
168 |
+
require_once( WPBDP_PATH . 'core/view-submit-listing.php' );
|
169 |
+
|
170 |
+
if ( wpbdp()->has_module( 'featuredlevels' ) )
|
171 |
+
wpbdp_admin()->messages[] = _x( 'This is a preview of the form as it will appear during "Submit a Listing". The users may not see all fields from "Manage Form Fields" because you have "Featured Levels" active and this is showing the base level.',
|
172 |
+
'formfields-preview',
|
173 |
+
'WPBDM' );
|
174 |
+
|
175 |
+
$html = '';
|
176 |
+
|
177 |
+
$html .= wpbdp_admin_header(_x('Form Preview', 'form-fields admin', 'WPBDM'), 'formfields-preview', array(
|
178 |
+
array(_x('← Return to "Manage Form Fields"', 'form-fields admin', 'WPBDM'), esc_url(remove_query_arg('action')))
|
179 |
+
));
|
180 |
+
$html .= wpbdp_admin_notices();
|
181 |
+
|
182 |
+
$controller = new WPBDP_Submit_Listing_Page( 0, true );
|
183 |
+
$html .= $controller->preview_listing_fields_form();
|
184 |
+
|
185 |
+
$html .= wpbdp_admin_footer();
|
186 |
+
|
187 |
+
echo $html;
|
188 |
+
}
|
189 |
+
|
190 |
+
/* field list */
|
191 |
+
private function fieldsTable() {
|
192 |
+
$table = new WPBDP_FormFieldsTable();
|
193 |
+
$table->prepare_items();
|
194 |
+
|
195 |
+
wpbdp_render_page(WPBDP_PATH . 'admin/templates/form-fields.tpl.php',
|
196 |
+
array('table' => $table),
|
197 |
+
true);
|
198 |
+
}
|
199 |
+
|
200 |
+
private function processFieldForm() {
|
201 |
+
$api = WPBDP_FormFields::instance();
|
202 |
+
|
203 |
+
|
204 |
+
if ( isset( $_POST['field'] ) ) {
|
205 |
+
$field = new WPBDP_FormField( stripslashes_deep( $_POST['field'] ) );
|
206 |
+
$res = $field->save();
|
207 |
+
|
208 |
+
if ( !is_wp_error( $res ) ) {
|
209 |
+
$this->admin->messages[] = _x( 'Form fields updated.', 'form-fields admin', 'WPBDM' );
|
210 |
+
return $this->fieldsTable();
|
211 |
+
} else {
|
212 |
+
$errmsg = '';
|
213 |
+
|
214 |
+
foreach ( $res->get_error_messages() as $err ) {
|
215 |
+
$errmsg .= sprintf( '• %s<br />', $err );
|
216 |
+
}
|
217 |
+
|
218 |
+
$this->admin->messages[] = array( $errmsg, 'error' );
|
219 |
+
}
|
220 |
+
} else {
|
221 |
+
$field = isset( $_GET['id'] ) ? WPBDP_FormField::get( $_GET['id'] ) : new WPBDP_FormField( array( 'display_flags' => array( 'excerpt', 'search', 'listing' ) ) );
|
222 |
+
}
|
223 |
+
|
224 |
+
wpbdp_render_page( WPBDP_PATH . 'admin/templates/form-fields-addoredit.tpl.php',
|
225 |
+
array(
|
226 |
+
'field' => $field,
|
227 |
+
'field_associations' => $api->get_associations_with_flags(),
|
228 |
+
'field_types' => $api->get_field_types(),
|
229 |
+
'validators' => $api->get_validators(),
|
230 |
+
'association_field_types' => $api->get_association_field_types()
|
231 |
+
),
|
232 |
+
true );
|
233 |
+
}
|
234 |
+
|
235 |
+
private function deleteField() {
|
236 |
+
global $wpdb;
|
237 |
+
|
238 |
+
$field = WPBDP_FormField::get( $_REQUEST['id'] );
|
239 |
+
|
240 |
+
if ( !$field || $field->has_behavior_flag( 'no-delete' ) )
|
241 |
+
return;
|
242 |
+
|
243 |
+
if ( isset( $_POST['doit'] ) ) {
|
244 |
+
$ret = $field->delete();
|
245 |
+
|
246 |
+
if ( is_wp_error( $ret ) ) {
|
247 |
+
$this->admin->messages[] = array( $ret->get_error_message(), 'error' );
|
248 |
+
} else {
|
249 |
+
$this->admin->messages[] = _x( 'Field deleted.', 'form-fields admin', 'WPBDM' );
|
250 |
+
}
|
251 |
+
|
252 |
+
return $this->fieldsTable();
|
253 |
+
}
|
254 |
+
|
255 |
+
wpbdp_render_page( WPBDP_PATH . 'admin/templates/form-fields-confirm-delete.tpl.php',
|
256 |
+
array( 'field' => $field ),
|
257 |
+
true );
|
258 |
+
}
|
259 |
+
|
260 |
+
private function createRequiredFields() {
|
261 |
+
global $wpbdp;
|
262 |
+
|
263 |
+
if ( $missing = $wpbdp->formfields->get_missing_required_fields() ) {
|
264 |
+
$wpbdp->formfields->create_default_fields( $missing );
|
265 |
+
$this->admin->messages[] = _x('Required fields created successfully.', 'form-fields admin', 'WPBDM');
|
266 |
+
}
|
267 |
+
|
268 |
+
return $this->fieldsTable();
|
269 |
+
}
|
270 |
+
|
271 |
+
}
|
admin/index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php
|
admin/js/listing.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var wpbdp = window.wpbdp || {};
|
2 |
+
var admin = wpbdp.admin = wpbdp.admin || {};
|
3 |
+
|
4 |
+
( function( $ ) {
|
5 |
+
var listing = admin.listing = admin.listing || {};
|
6 |
+
|
7 |
+
var images = listing.images = wpbdp.admin.listing.images = {
|
8 |
+
init: function() {
|
9 |
+
var t = this;
|
10 |
+
|
11 |
+
// Handle image deletes.
|
12 |
+
$( '#wpbdp-uploaded-images' ).delegate( '.delete-image', 'click', function( e ) {
|
13 |
+
e.preventDefault();
|
14 |
+
$.post( $( this ).attr( 'data-action' ), {}, function( res ) {
|
15 |
+
if ( ! res.success )
|
16 |
+
return;
|
17 |
+
|
18 |
+
$( '#wpbdp-uploaded-images .wpbdp-image[data-imageid="' + res.data.imageId + '"]' ).remove();
|
19 |
+
|
20 |
+
if ( 0 == $( '#wpbdp-uploaded-images .wpbdp-image' ).length )
|
21 |
+
$( '#no-images-message' ).show();
|
22 |
+
}, 'json' );
|
23 |
+
} );
|
24 |
+
|
25 |
+
// Image upload.
|
26 |
+
wpbdp.dnd.setup( $( '#image-upload-dnd-area' ), {
|
27 |
+
done: function( res ) {
|
28 |
+
$( '#no-images-message' ).hide();
|
29 |
+
$( '#wpbdp-uploaded-images' ).append( res.data.html );
|
30 |
+
}
|
31 |
+
} );
|
32 |
+
}
|
33 |
+
};
|
34 |
+
|
35 |
+
// Initialization.
|
36 |
+
$( document ).ready( function() {
|
37 |
+
images.init();
|
38 |
+
} );
|
39 |
+
|
40 |
+
} )( jQuery );
|
admin/js/listing.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
var wpbdp=window.wpbdp||{};var admin=wpbdp.admin=wpbdp.admin||{};(function($){var listing=admin.listing=admin.listing||{};var images=listing.images=wpbdp.admin.listing.images={init:function(){var t=this;$("#wpbdp-uploaded-images").delegate(".delete-image","click",function(e){e.preventDefault();$.post($(this).attr("data-action"),{},function(res){if(!res.success){return}$('#wpbdp-uploaded-images .wpbdp-image[data-imageid="'+res.data.imageId+'"]').remove();if(0==$("#wpbdp-uploaded-images .wpbdp-image").length){$("#no-images-message").show()}},"json")});wpbdp.dnd.setup($("#image-upload-dnd-area"),{done:function(res){$("#no-images-message").hide();$("#wpbdp-uploaded-images").append(res.data.html)}})}};$(document).ready(function(){images.init()})})(jQuery);
|
admin/listing-metabox.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPBDP_Admin_Listing_Metabox {
|
3 |
+
|
4 |
+
private $listing = null;
|
5 |
+
|
6 |
+
public function __construct( $listing_id ) {
|
7 |
+
$this->listing = WPBDP_Listing::get( $listing_id );
|
8 |
+
}
|
9 |
+
|
10 |
+
public function render() {
|
11 |
+
$tabs = array( 'generalinfo' => _x('General', 'admin', 'WPBDM'),
|
12 |
+
'fees' => _x('Fee Details', 'admin', 'WPBDM'),
|
13 |
+
'transactions' => _x('Transactions', 'admin', 'WPBDM') );
|
14 |
+
|
15 |
+
// Determine selected tab.
|
16 |
+
$selected_tab = 'generalinfo';
|
17 |
+
if ( isset( $_GET['wpbdmaction'] ) && in_array( $_GET['wpbdmaction'], array( 'removecategory', 'assignfee', 'change_expiration' ), true ) )
|
18 |
+
$selected_tab = 'fees';
|
19 |
+
$selected_tab = 'fees';
|
20 |
+
|
21 |
+
echo '<div class="misc-pub-section">';
|
22 |
+
|
23 |
+
echo '<ul class="listing-metabox-tabs">';
|
24 |
+
foreach ( $tabs as $tab_id => $tab_label ) {
|
25 |
+
echo '<li class="tabs ' . ( $selected_tab === $tab_id ? 'selected' : '' ) . '"><a href="#listing-metabox-' . $tab_id . '">' . $tab_label .'</a></li>';
|
26 |
+
}
|
27 |
+
echo '</ul>';
|
28 |
+
|
29 |
+
foreach ( array_keys( $tabs ) as $tab_id ) {
|
30 |
+
echo '<div id="listing-metabox-' . $tab_id . '" class="listing-metabox-tab">';
|
31 |
+
call_user_func( array( &$this, 'tab_' . $tab_id ) );
|
32 |
+
echo '</div>';
|
33 |
+
}
|
34 |
+
|
35 |
+
echo '</div>';
|
36 |
+
echo '<div class="clear"></div>';
|
37 |
+
}
|
38 |
+
|
39 |
+
private function tab_generalinfo() {
|
40 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
41 |
+
|
42 |
+
echo '<strong>' . _x('General Info', 'admin infometabox', 'WPBDM') . '</strong>';
|
43 |
+
echo '<dl>';
|
44 |
+
echo '<dt>'. _x('Total Listing Cost', 'admin infometabox', 'WPBDM') . '</dt>';
|
45 |
+
echo '<dd>' . wpbdp_format_currency( $this->listing->get_total_cost() ) . '</dd>';
|
46 |
+
echo '<dt>'. _x('Payment Status', 'admin infometabox', 'WPBDM') . '</dt>';
|
47 |
+
echo '<dd>';
|
48 |
+
echo sprintf('<span class="tag paymentstatus %1$s">%1$s</span>', $this->listing->get_payment_status() );
|
49 |
+
echo '</dd>';
|
50 |
+
echo '<dt>' . _x('Featured (Sticky) Status', 'admin infometabox', 'WPBDM') . '</dt>';
|
51 |
+
echo '<dd>';
|
52 |
+
|
53 |
+
// sticky information
|
54 |
+
$sticky_info = $upgrades_api->get_info( $this->listing->get_id() );
|
55 |
+
|
56 |
+
echo '<span><b>';
|
57 |
+
if ($sticky_info->pending) {
|
58 |
+
echo _x('Pending Upgrade', 'admin metabox', 'WPBDM');
|
59 |
+
} else {
|
60 |
+
echo esc_attr( $sticky_info->level->name );
|
61 |
+
}
|
62 |
+
echo '</b> </span><br />';
|
63 |
+
|
64 |
+
if (current_user_can('administrator')) {
|
65 |
+
if ( $sticky_info->upgradeable ) {
|
66 |
+
echo sprintf('<span><a href="%s">%s</a></span>',
|
67 |
+
add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->upgrade->id, 'post' => $this->listing->get_id())),
|
68 |
+
'<b>↑</b> ' . sprintf(__('Upgrade to %s', 'WPBDM'), esc_attr($sticky_info->upgrade->name)) );
|
69 |
+
}
|
70 |
+
|
71 |
+
if ( $sticky_info->downgradeable ) {
|
72 |
+
echo '<br />';
|
73 |
+
echo sprintf('<span><a href="%s">%s</a></span>',
|
74 |
+
add_query_arg(array('wpbdmaction' => 'changesticky', 'u' => $sticky_info->downgrade->id, 'post' => $this->listing->get_id())),
|
75 |
+
'<b>↓</b> ' . sprintf(__('Downgrade to %s', 'WPBDM'), esc_attr($sticky_info->downgrade->name)) );
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
$import_id = get_post_meta( $this->listing->get_id(), '_wpbdp[import_sequence_id]', true );
|
80 |
+
if ( current_user_can( 'administrator' ) && $import_id ) {
|
81 |
+
echo '<dt>' . _x( 'CSV Import Sequence ID', 'admin infometabox', 'WPBDM' ) . '</dt>';
|
82 |
+
echo '<dd>' . $import_id . '</dd>';
|
83 |
+
}
|
84 |
+
|
85 |
+
echo '</dd>';
|
86 |
+
do_action( 'wpbdp_admin_metabox_generalinfo_list', $this->listing->get_id() );
|
87 |
+
echo '</dl>';
|
88 |
+
|
89 |
+
if ( current_user_can( 'administrator' ) && 'ok' != $this->listing->get_payment_status() ) {
|
90 |
+
echo sprintf( '<a href="%s" class="button-primary">%s</a> ',
|
91 |
+
add_query_arg('wpbdmaction', 'setaspaid' ),
|
92 |
+
_x( 'Mark listing as Paid', 'admin infometabox', 'WPBDM' ) );
|
93 |
+
}
|
94 |
+
|
95 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-metabox-feesummary.tpl.php', array(
|
96 |
+
'categories' => $this->listing->get_categories( 'all' ),
|
97 |
+
'listing' => $this->listing
|
98 |
+
) );
|
99 |
+
}
|
100 |
+
|
101 |
+
private function tab_fees() {
|
102 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-metabox-fees.tpl.php', array(
|
103 |
+
'categories' => $this->listing->get_categories( 'all' ),
|
104 |
+
'listing' => $this->listing
|
105 |
+
) );
|
106 |
+
}
|
107 |
+
|
108 |
+
private function tab_transactions() {
|
109 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-metabox-transactions.tpl.php',
|
110 |
+
array( 'payments' => $this->listing->get_latest_payments() ) );
|
111 |
+
}
|
112 |
+
|
113 |
+
public static function metabox_callback( $post ) {
|
114 |
+
$instance = new self( $post->ID );
|
115 |
+
return $instance->render();
|
116 |
+
}
|
117 |
+
}
|
admin/page-debug.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_Admin_Debug_Page {
|
4 |
+
|
5 |
+
function __construct() {
|
6 |
+
add_action( 'admin_init', array($this, 'handle_download' ) );
|
7 |
+
}
|
8 |
+
|
9 |
+
function dispatch( $plain = false ) {
|
10 |
+
global $wpdb;
|
11 |
+
|
12 |
+
$debug_info = array();
|
13 |
+
|
14 |
+
// basic BD setup info & tests
|
15 |
+
$debug_info['basic']['_title'] = _x( 'BD Info', 'debug-info', 'WPBDM' );
|
16 |
+
$debug_info['basic']['BD version'] = WPBDP_VERSION;
|
17 |
+
$debug_info['basic']['BD database revision (current)'] = WPBDP_Installer::DB_VERSION;
|
18 |
+
$debug_info['basic']['BD database revision (installed)'] = get_option( 'wpbdp-db-version' );
|
19 |
+
|
20 |
+
$tables = apply_filters( 'wpbdp_debug_info_tables_check', array( 'wpbdp_form_fields', 'wpbdp_fees', 'wpbdp_payments', 'wpbdp_listing_fees' ) );
|
21 |
+
$missing_tables = array();
|
22 |
+
foreach ( $tables as &$t ) {
|
23 |
+
if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . $t) ) == '' )
|
24 |
+
$missing_tables[] = $t;
|
25 |
+
}
|
26 |
+
$debug_info['basic']['Table check'] = $missing_tables
|
27 |
+
? sprintf( _( 'Missing tables: %s', 'debug-info', 'WPBDM' ), implode(',', $missing_tables) )
|
28 |
+
: _x( 'OK', 'debug-info', 'WPBDM' );
|
29 |
+
|
30 |
+
$debug_info['basic']['Main Page'] = sprintf( '%d (%s)', wpbdp_get_page_id( 'main' ), get_post_status( wpbdp_get_page_id( 'main' ) ) );
|
31 |
+
$debug_info['basic'] = apply_filters( 'wpbdp_debug_info_section', $debug_info['basic'], 'basic' );
|
32 |
+
|
33 |
+
|
34 |
+
// BD options
|
35 |
+
$blacklisted = array( 'googlecheckout-merchant', 'paypal-business-email', 'wpbdp-2checkout-seller', 'recaptcha-public-key', 'recaptcha-private-key' );
|
36 |
+
$debug_info['options']['_title'] = _x( 'BD Options', 'debug-info', 'WPBDM' );
|
37 |
+
|
38 |
+
$settings_api = wpbdp_settings_api();
|
39 |
+
foreach ( $settings_api->settings as &$s ) {
|
40 |
+
if ( $s->type == 'core' || in_array( $s->name, $blacklisted ) )
|
41 |
+
continue;
|
42 |
+
|
43 |
+
$value = wpbdp_get_option( $s->name );
|
44 |
+
$debug_info['options'][ $s->name ] = is_array( $value ) ? implode( ',', $value ) : $value;
|
45 |
+
}
|
46 |
+
$debug_info['options'] = apply_filters( 'wpbdp_debug_info_section', $debug_info['options'], 'options' );
|
47 |
+
|
48 |
+
// environment info
|
49 |
+
$debug_info['environment']['_title'] = _x( 'Environment', 'debug-info', 'WPBDM' );
|
50 |
+
$debug_info['environment']['WordPress version'] = get_bloginfo( 'version', 'raw' );
|
51 |
+
$debug_info['environment']['OS'] = php_uname( 's' ) . ' ' . php_uname( 'r' ) . ' ' . php_uname( 'm' );
|
52 |
+
|
53 |
+
if ( function_exists( 'apache_get_version' ) ) {
|
54 |
+
$apache_version = apache_get_version();
|
55 |
+
$debug_info['environment']['Apache version'] = $apache_version;
|
56 |
+
}
|
57 |
+
|
58 |
+
$debug_info['environment']['PHP version'] = phpversion();
|
59 |
+
|
60 |
+
$mysql_version = $wpdb->get_var( 'SELECT @@version' );
|
61 |
+
if ( $sql_mode = $wpdb->get_var( 'SELECT @@sql_mode' ) )
|
62 |
+
$mysql_version .= ' ( ' . $sql_mode . ' )';
|
63 |
+
$debug_info['environment']['MySQL version'] = $mysql_version ? $mysql_version : 'N/A';
|
64 |
+
|
65 |
+
$sqlite_version = class_exists('SQLite3') ? wpbdp_getv( SQLite3::version(), 'versionString', '' ): ( function_exists( 'sqlite_libversion' ) ? sqlite_libversion() : null );
|
66 |
+
$debug_info['environment']['SQLite version'] = $sqlite_version ? $sqlite_version : 'N/A';
|
67 |
+
|
68 |
+
$debug_info['environment']['cURL version'] = function_exists( 'curl_init' ) ? wpbdp_getv( curl_version(), 'version' ) : 'N/A';
|
69 |
+
|
70 |
+
$debug_info['environment'] = apply_filters( 'wpbdp_debug_info_section', $debug_info['environment'], 'environment' );
|
71 |
+
|
72 |
+
$debug_info = apply_filters( 'wpbdp_debug_info', $debug_info );
|
73 |
+
|
74 |
+
if ( $plain ) {
|
75 |
+
foreach ( $debug_info as &$section ) {
|
76 |
+
foreach ( $section as $k => $v ) {
|
77 |
+
if ( $k == '_title' ) {
|
78 |
+
printf( '== %s ==', $v );
|
79 |
+
print PHP_EOL;
|
80 |
+
continue;
|
81 |
+
}
|
82 |
+
|
83 |
+
printf( "%-33s = %s", $k, $v );
|
84 |
+
print PHP_EOL;
|
85 |
+
}
|
86 |
+
|
87 |
+
print str_repeat( PHP_EOL, 2 );
|
88 |
+
}
|
89 |
+
return;
|
90 |
+
}
|
91 |
+
|
92 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/debug-info.tpl.php', array( 'debug_info' => $debug_info ) );
|
93 |
+
}
|
94 |
+
|
95 |
+
function handle_download() {
|
96 |
+
global $pagenow;
|
97 |
+
|
98 |
+
if ( ! current_user_can( 'administrator' ) || 'admin.php' != $pagenow
|
99 |
+
|| ! isset( $_GET['page'] ) || 'wpbdp-debug-info' != $_GET['page'] )
|
100 |
+
return;
|
101 |
+
|
102 |
+
if ( isset( $_GET['download'] ) && 1 == $_GET['download'] ) {
|
103 |
+
header( 'Content-Description: File Transfer' );
|
104 |
+
header( 'Content-Type: text/plain; charset=' . get_option( 'blog_charset' ), true );
|
105 |
+
header( 'Content-Disposition: attachment; filename=' . 'wpbdp-debug-info.txt' );
|
106 |
+
header( 'Pragma: no-cache' );
|
107 |
+
$this->dispatch( true );
|
108 |
+
exit;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
admin/payments.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-payment.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Payments admin page and AJAX actions.
|
6 |
+
* @since 3.4
|
7 |
+
*/
|
8 |
+
class WPBDP_Admin_Payments {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
add_action( 'wp_ajax_wpbdp-payment-details', array( &$this, 'ajax_payment_details' ) );
|
12 |
+
}
|
13 |
+
|
14 |
+
public function ajax_payment_details() {
|
15 |
+
if ( ! current_user_can( 'administrator' ) )
|
16 |
+
exit();
|
17 |
+
|
18 |
+
global $wpbdp;
|
19 |
+
|
20 |
+
$response = new WPBDP_AJAX_Response();
|
21 |
+
|
22 |
+
$payment = WPBDP_Payment::get( intval( $_REQUEST['id'] ) );
|
23 |
+
if ( ! $payment )
|
24 |
+
$response->send_error();
|
25 |
+
|
26 |
+
$response->add( 'html', wpbdp_render_page( WPBDP_PATH . 'admin/templates/payment-details.tpl.php',
|
27 |
+
array( 'payment' => $payment,
|
28 |
+
'invoice' => $wpbdp->payments->render_invoice( $payment ) ) ) );
|
29 |
+
$response->send();
|
30 |
+
}
|
31 |
+
|
32 |
+
}
|
admin/resources/2checkout-gateway-module.png
ADDED
Binary file
|
admin/resources/admin.css
ADDED
@@ -0,0 +1,773 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cf:before, .cf:after {
|
2 |
+
content: " ";
|
3 |
+
display: table;
|
4 |
+
}
|
5 |
+
|
6 |
+
.cf:after {
|
7 |
+
clear: both;
|
8 |
+
}
|
9 |
+
.cf {
|
10 |
+
*zoom: 1;
|
11 |
+
}
|
12 |
+
|
13 |
+
span.tag {
|
14 |
+
background: #444;
|
15 |
+
border-radius: 2px;
|
16 |
+
padding: 2px 5px;
|
17 |
+
color: #fff;
|
18 |
+
font-size: 9px !important;
|
19 |
+
margin-right: 2px;
|
20 |
+
text-transform: uppercase;
|
21 |
+
text-decoration: none !important;
|
22 |
+
line-height: 1.5 !important;
|
23 |
+
}
|
24 |
+
|
25 |
+
/* Sidebar */
|
26 |
+
.wpbdp-admin-content.with-sidebar {
|
27 |
+
margin-top: 20px;
|
28 |
+
/*float: left;*/
|
29 |
+
/*width: 80%;*/
|
30 |
+
/*margin-right: 300px;*/
|
31 |
+
clear: left;
|
32 |
+
float: left;
|
33 |
+
width: 78%;
|
34 |
+
}
|
35 |
+
|
36 |
+
.wpbdp-admin .sidebar {
|
37 |
+
margin-top: 20px;
|
38 |
+
float: right;
|
39 |
+
clear: right;
|
40 |
+
width: 20%;
|
41 |
+
}
|
42 |
+
|
43 |
+
.wpbdp-admin .sidebar .postbox {
|
44 |
+
min-width: 0 !important;
|
45 |
+
}
|
46 |
+
|
47 |
+
.wpbdp-admin .sidebar .premium-modules h3 span {
|
48 |
+
color: #145200;
|
49 |
+
font-weight: bold;
|
50 |
+
}
|
51 |
+
|
52 |
+
.wpbdp-admin .sidebar .premium-modules {
|
53 |
+
border-color: #0EAD00;
|
54 |
+
border-width: 3px;
|
55 |
+
background: #FFFFCF;
|
56 |
+
}
|
57 |
+
|
58 |
+
/* {{{ "Manage Fees" page. */
|
59 |
+
|
60 |
+
.wpbdp-page-admin-fees .wp-list-table .wpbdp-drag-handle {
|
61 |
+
margin-right: 15px;
|
62 |
+
display: none;
|
63 |
+
}
|
64 |
+
|
65 |
+
.wpbdp-page-admin-fees .purchase-gateways {
|
66 |
+
margin-left: 20px;
|
67 |
+
}
|
68 |
+
|
69 |
+
.wpbdp-page-admin-fees .purchase-gateways .gateway {
|
70 |
+
float: left;
|
71 |
+
width: 35%;
|
72 |
+
margin: 30px 20px 0 0;
|
73 |
+
/* height: 180px;*/
|
74 |
+
}
|
75 |
+
|
76 |
+
.wpbdp-page-admin-fees .purchase-gateways .gateway.installed {
|
77 |
+
opacity: 0.5;
|
78 |
+
}
|
79 |
+
|
80 |
+
.wpbdp-page-admin-fees .purchase-gateways .gateway a img.gateway-logo {
|
81 |
+
/* width: 30%;*/
|
82 |
+
height: 40px;
|
83 |
+
margin: 0;
|
84 |
+
padding: 0;
|
85 |
+
border: none;
|
86 |
+
}
|
87 |
+
|
88 |
+
.wpbdp-page-admin-fees .purchase-gateways .gateway a.price {
|
89 |
+
margin-top: 10px;
|
90 |
+
display: block;
|
91 |
+
color: green;
|
92 |
+
font-size: 22px;
|
93 |
+
font-weight: bold;
|
94 |
+
}
|
95 |
+
|
96 |
+
.wpbdp-page-admin-fees .purchase-gateways .gateway .check-mark {
|
97 |
+
font-size: 150%;
|
98 |
+
font-weight: bold;
|
99 |
+
color: green;
|
100 |
+
}
|
101 |
+
|
102 |
+
/* }}} */
|
103 |
+
|
104 |
+
/* Directory list-table */
|
105 |
+
td.column-payment_status .status, td.column-sticky_status .status {
|
106 |
+
background: #444;
|
107 |
+
border-radius: 2px;
|
108 |
+
padding: 2px 5px;
|
109 |
+
color: #fff;
|
110 |
+
font-size: 90%;
|
111 |
+
}
|
112 |
+
|
113 |
+
td.column-payment_status .status.ok {
|
114 |
+
background: green;
|
115 |
+
}
|
116 |
+
|
117 |
+
td.column-payment_status .paymentdata {
|
118 |
+
font-size: 85%;
|
119 |
+
}
|
120 |
+
|
121 |
+
td.column-payment_status .paymentdata b {
|
122 |
+
font-weight: normal;
|
123 |
+
}
|
124 |
+
|
125 |
+
td.column-payment_status .paymentdata span {
|
126 |
+
font-style: italic;
|
127 |
+
}
|
128 |
+
|
129 |
+
td.column-sticky_status .status.notpaid {
|
130 |
+
background: orange;
|
131 |
+
}
|
132 |
+
|
133 |
+
td.column-sticky_status .status.pending {
|
134 |
+
background: red;
|
135 |
+
font-weight: bold;
|
136 |
+
}
|
137 |
+
|
138 |
+
td.column-sticky_status .status.sticky {
|
139 |
+
background: green;
|
140 |
+
}
|
141 |
+
|
142 |
+
/* Form fields list table */
|
143 |
+
table.wp-list-table td .tag {
|
144 |
+
background: #444;
|
145 |
+
border-radius: 2px;
|
146 |
+
padding: 2px 5px;
|
147 |
+
color: #fff;
|
148 |
+
font-size: 90%;
|
149 |
+
margin-right: 2px;
|
150 |
+
}
|
151 |
+
|
152 |
+
table.wp-list-table.formfields th.column-label {
|
153 |
+
width: 40%;
|
154 |
+
}
|
155 |
+
|
156 |
+
table.wp-list-table.formfields th.column-tags, table.wp-list-table.formfields td.column-tags {
|
157 |
+
width: 200px;
|
158 |
+
}
|
159 |
+
|
160 |
+
table.wp-list-table.formfields th.column-order, table.wp-list-table.formfields td.column-order {
|
161 |
+
width: 55px;
|
162 |
+
}
|
163 |
+
|
164 |
+
table.wp-list-table.formfields td.column-order .wpbdp-drag-handle {
|
165 |
+
visibility: hidden;
|
166 |
+
}
|
167 |
+
|
168 |
+
/*table.wp-list-table.formfields tbody tr:hover {
|
169 |
+
cursor: move;
|
170 |
+
}*/
|
171 |
+
|
172 |
+
table.wp-list-table.formfields tr:hover .wpbdp-drag-handle {
|
173 |
+
visibility: visible;
|
174 |
+
}
|
175 |
+
|
176 |
+
table.wp-list-table.formfields .tag.required {
|
177 |
+
background: orange;
|
178 |
+
}
|
179 |
+
|
180 |
+
table.wp-list-table.formfields .tag.in-excerpt {
|
181 |
+
background: green;
|
182 |
+
}
|
183 |
+
|
184 |
+
table.wp-list-table.formfields .tag.in-listing {
|
185 |
+
background: green;
|
186 |
+
}
|
187 |
+
|
188 |
+
table.wp-list-table.formfields tr.wpbdp-draggable-highlight {
|
189 |
+
height: 54px;
|
190 |
+
}
|
191 |
+
|
192 |
+
table.wp-list-table.formfields tr.ui-sortable-helper {
|
193 |
+
background: #fff;
|
194 |
+
border: 1px dashed #c1c1c1;
|
195 |
+
}
|
196 |
+
|
197 |
+
#wpbdp-listing-fields input[type="text"] {
|
198 |
+
width: 70%;
|
199 |
+
}
|
200 |
+
|
201 |
+
#wpbdp-listing-fields .wpbdp-form-field.url .wpbdp-form-field-html {
|
202 |
+
padding-left: 10px;
|
203 |
+
}
|
204 |
+
|
205 |
+
#wpbdp-listing-fields .wpbdp-form-field.url input[type="text"] {
|
206 |
+
display: block;
|
207 |
+
}
|
208 |
+
|
209 |
+
#wpbdp-listing-fields #wpbdp-uploaded-images .wpbdp-image {
|
210 |
+
padding: 5px;
|
211 |
+
/*border-right: 1px solid #ddd;*/
|
212 |
+
width: 150px;
|
213 |
+
vertical-align: top;
|
214 |
+
/*float: left;*/
|
215 |
+
display: inline-block;
|
216 |
+
zoom: 1;
|
217 |
+
*display: inline;
|
218 |
+
min-height: 210px;
|
219 |
+
_height: 210px;
|
220 |
+
}
|
221 |
+
|
222 |
+
#wpbdp-listing-fields div.listing-images .image img {
|
223 |
+
max-width: 150px;
|
224 |
+
}
|
225 |
+
|
226 |
+
|
227 |
+
/* FIXME: some front-end styles */
|
228 |
+
ul#wpbusdirmanerrors { margin-left:20px; }
|
229 |
+
|
230 |
+
/* CSV import */
|
231 |
+
.wpbdp-csv-import-example {
|
232 |
+
width: 100%;
|
233 |
+
padding: 10px;
|
234 |
+
display: block;
|
235 |
+
background: #fff;
|
236 |
+
border: solid 1px #ddd;
|
237 |
+
font-size: 90%;
|
238 |
+
font-family: monospace;
|
239 |
+
height: 100%;
|
240 |
+
white-space: pre;
|
241 |
+
}
|
242 |
+
|
243 |
+
#wpbdp-csv-import-form input[type="file"] {
|
244 |
+
border: none;
|
245 |
+
}
|
246 |
+
|
247 |
+
table.wpbdp-csv-import-results, table.wpbdp-csv-import-warnings {
|
248 |
+
width: 100%;
|
249 |
+
}
|
250 |
+
|
251 |
+
table.wpbdp-csv-import-results .line-no, table.wpbdp-csv-import-warnings .line-no {
|
252 |
+
width: 50px;
|
253 |
+
}
|
254 |
+
|
255 |
+
table.wpbdp-csv-import-results td.line, table.wpbdp-csv-import-warnings td.line {
|
256 |
+
font-family: monospace;
|
257 |
+
font-size: 90%;
|
258 |
+
}
|
259 |
+
|
260 |
+
table.wpbdp-csv-import-results .error, table.wpbdp-csv-import-warnings .error {
|
261 |
+
width: 200px;
|
262 |
+
}
|
263 |
+
|
264 |
+
table.wpbdp-csv-import-headers {
|
265 |
+
width: 100%;
|
266 |
+
}
|
267 |
+
|
268 |
+
table.wpbdp-csv-import-headers td.field-is-required, table.wpbdp-csv-import-headers td.field-is-multivalued {
|
269 |
+
text-align: center;
|
270 |
+
}
|
271 |
+
|
272 |
+
table.wpbdp-csv-import-headers tbody tr {
|
273 |
+
background: #f9f9f9;
|
274 |
+
}
|
275 |
+
|
276 |
+
table.wpbdp-csv-import-headers tbody tr.alt {
|
277 |
+
background: inherit;
|
278 |
+
}
|
279 |
+
|
280 |
+
.wpbdp-form-field.image .preview {
|
281 |
+
float: none;
|
282 |
+
}
|
283 |
+
|
284 |
+
/* Debug info */
|
285 |
+
table.wpbdp-debug-section {
|
286 |
+
width: 90%;
|
287 |
+
}
|
288 |
+
|
289 |
+
table.wpbdp-debug-section tbody tr {
|
290 |
+
background: #efefef;
|
291 |
+
}
|
292 |
+
|
293 |
+
table.wpbdp-debug-section tbody tr td {
|
294 |
+
padding: 3px 8px;
|
295 |
+
}
|
296 |
+
|
297 |
+
table.wpbdp-debug-section tbody tr:nth-child(2n) {
|
298 |
+
background: #f5f5f5;
|
299 |
+
}
|
300 |
+
|
301 |
+
/* Transactions admin */
|
302 |
+
.wpbdp-page-admin-transactions .tag {
|
303 |
+
font-size: 95%;
|
304 |
+
}
|
305 |
+
|
306 |
+
.wpbdp-page-admin-transactions .tag.approved {
|
307 |
+
background: green;
|
308 |
+
}
|
309 |
+
|
310 |
+
.wpbdp-page-admin-transactions .tag.pending {
|
311 |
+
background: red;
|
312 |
+
}
|
313 |
+
|
314 |
+
.wpbdp-page-admin-transactions .tag.rejected {
|
315 |
+
}
|
316 |
+
|
317 |
+
.wpbdp-page-admin-transactions .column-actions a.delete {
|
318 |
+
color: #bc0b0b;
|
319 |
+
}
|
320 |
+
|
321 |
+
.wpbdp-page-admin-transactions tr.more-details-row {
|
322 |
+
background: #fff;
|
323 |
+
}
|
324 |
+
|
325 |
+
.wpbdp-page-admin-transactions tr.more-details-row td {
|
326 |
+
padding-left: 40px;
|
327 |
+
font-size: 95%;
|
328 |
+
}
|
329 |
+
|
330 |
+
.wpbdp-page-admin-transactions tr.more-details-row td dl dt {
|
331 |
+
font-weight: bold;
|
332 |
+
}
|
333 |
+
|
334 |
+
/*ul.subsubsub li.paid {
|
335 |
+
margin-left: 20px;
|
336 |
+
}*/
|
337 |
+
|
338 |
+
body.taxonomy-wpbdp_category .column-id {
|
339 |
+
width: 35px;
|
340 |
+
}
|
341 |
+
|
342 |
+
.transaction-status-container {
|
343 |
+
text-align: right;
|
344 |
+
padding: 5px;
|
345 |
+
}
|
346 |
+
|
347 |
+
/* -- Progress bar. -- */
|
348 |
+
.wpbpd-progress-bar {
|
349 |
+
}
|
350 |
+
|
351 |
+
.wpbpd-progress-bar .progress-text {
|
352 |
+
}
|
353 |
+
|
354 |
+
.wpbdp-progress-bar .progress-bar {
|
355 |
+
margin-left: 10px;
|
356 |
+
display: inline-block;
|
357 |
+
vertical-align: middle;
|
358 |
+
}
|
359 |
+
|
360 |
+
.wpbdp-progress-bar .progress-bar-outer {
|
361 |
+
min-width: 200px;
|
362 |
+
height: 12px;
|
363 |
+
border: solid 1px #3366CC;
|
364 |
+
padding: 0;
|
365 |
+
}
|
366 |
+
|
367 |
+
.wpbdp-progress-bar .progress-bar-inner {
|
368 |
+
height: 100%;
|
369 |
+
background: #99CCFF;
|
370 |
+
}
|
371 |
+
|
372 |
+
/* -- WPBDP note messages. */
|
373 |
+
.wpbdp-note {
|
374 |
+
padding: 5px 10px;
|
375 |
+
background: #d7f5ff;
|
376 |
+
margin: 5px 0 20px 0;
|
377 |
+
border: solid 1px #bad5df;
|
378 |
+
border-radius: 4px;
|
379 |
+
}
|
380 |
+
|
381 |
+
.wpbdp-note p {
|
382 |
+
margin: 0;
|
383 |
+
}
|
384 |
+
|
385 |
+
.wpbdp-note h1, .wpbdp-note h2, .wpbdp-note h3, .wpbdp-note h4 {
|
386 |
+
margin: 0 0 8px 0;
|
387 |
+
}
|
388 |
+
|
389 |
+
/* Admin settings. */
|
390 |
+
.directory-admin_page_wpbdp_admin_settings table.form-table th, .directory-admin_page_wpbdp_admin_settings table.form-table td {
|
391 |
+
font-size: 13px;
|
392 |
+
line-height: 1.0;
|
393 |
+
padding: 8px 20px;
|
394 |
+
}
|
395 |
+
|
396 |
+
.directory-admin_page_wpbdp_admin_settings table.form-table th {
|
397 |
+
min-width: 150px;
|
398 |
+
}
|
399 |
+
|
400 |
+
.directory-admin_page_wpbdp_admin_settings input, .directory-admin_page_wpbdp_admin_settings select {
|
401 |
+
font-size: 13px;
|
402 |
+
line-height: 1.0;
|
403 |
+
}
|
404 |
+
|
405 |
+
.directory-admin_page_wpbdp_admin_settings textarea {
|
406 |
+
font-size: 13px;
|
407 |
+
width: 95%;
|
408 |
+
}
|
409 |
+
|
410 |
+
.directory-admin_page_wpbdp_admin_settings select {
|
411 |
+
display: block;
|
412 |
+
}
|
413 |
+
|
414 |
+
.directory-admin_page_wpbdp_admin_settings .license-activation .status-message {
|
415 |
+
font-size: 85%;
|
416 |
+
color: #595959;
|
417 |
+
font-style: italic;
|
418 |
+
}
|
419 |
+
|
420 |
+
.directory-admin_page_wpbdp_admin_settings .license-activation .status-message.ok {
|
421 |
+
color: green;
|
422 |
+
}
|
423 |
+
|
424 |
+
.directory-admin_page_wpbdp_admin_settings .license-activation .status-message.error {
|
425 |
+
color: red;
|
426 |
+
}
|
427 |
+
|
428 |
+
.directory-admin_page_wpbdp_admin_settings .group-error {
|
429 |
+
border-top: solid 1px red;
|
430 |
+
}
|
431 |
+
|
432 |
+
.directory-admin_page_wpbdp_admin_settings .group-warning {
|
433 |
+
border-top: solid 1px yellow;
|
434 |
+
}
|
435 |
+
|
436 |
+
|
437 |
+
.tag.paymentstatus.ok {
|
438 |
+
background: green;
|
439 |
+
}
|
440 |
+
|
441 |
+
.tag.paymentstatus.completed {
|
442 |
+
background: green;
|
443 |
+
}
|
444 |
+
|
445 |
+
.tag.paymentstatus.pending {
|
446 |
+
background: red;
|
447 |
+
}
|
448 |
+
|
449 |
+
#wpbdp-admin-settings tr.disabled {
|
450 |
+
opacity: 0.7;
|
451 |
+
}
|
452 |
+
|
453 |
+
#wpbdp-admin-settings .text-fields-warning {
|
454 |
+
font-size: 90%;
|
455 |
+
display: block;
|
456 |
+
margin-bottom: 2px;
|
457 |
+
}
|
458 |
+
|
459 |
+
#wpbdp-admin-settings .wpbdp-settings-email {
|
460 |
+
margin: 5px 0 0 0;
|
461 |
+
border: solid 1px #ccc;
|
462 |
+
padding: 5px;
|
463 |
+
background: #fff;
|
464 |
+
}
|
465 |
+
|
466 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview {
|
467 |
+
color: #999;
|
468 |
+
font-size: 90%;
|
469 |
+
height: 45px;
|
470 |
+
cursor: pointer;
|
471 |
+
overflow: hidden;
|
472 |
+
}
|
473 |
+
|
474 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview h4 {
|
475 |
+
margin: 0 0 10px 0;
|
476 |
+
}
|
477 |
+
|
478 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview .edit-toggle {
|
479 |
+
/* visibility: hidden;*/
|
480 |
+
float: right;
|
481 |
+
}
|
482 |
+
|
483 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview:hover .edit-toggle {
|
484 |
+
visibility: visible;
|
485 |
+
}
|
486 |
+
|
487 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview dl {
|
488 |
+
margin: 0;
|
489 |
+
padding: 0;
|
490 |
+
}
|
491 |
+
|
492 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview dt {
|
493 |
+
font-weight: bold;
|
494 |
+
margin: 0;
|
495 |
+
padding: 0;
|
496 |
+
}
|
497 |
+
|
498 |
+
#wpbdp-admin-settings .wpbdp-settings-email .short-preview dd {
|
499 |
+
margin: 0;
|
500 |
+
padding: 0 0 0 10px;
|
501 |
+
}
|
502 |
+
|
503 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor {
|
504 |
+
margin-left: 10px;
|
505 |
+
font-size: 90%;
|
506 |
+
}
|
507 |
+
|
508 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor table.form-table {
|
509 |
+
margin: 0;
|
510 |
+
padding: 0;
|
511 |
+
}
|
512 |
+
|
513 |
+
#wpbdp-admin-settings .wpbdp-settings-email table.form-table th {
|
514 |
+
padding-left: 4px;
|
515 |
+
padding-right: 0;
|
516 |
+
min-width: 0;
|
517 |
+
width: 20%;
|
518 |
+
}
|
519 |
+
|
520 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor input[type="text"] {
|
521 |
+
width: 70%;
|
522 |
+
}
|
523 |
+
|
524 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor textarea {
|
525 |
+
width: 100%;
|
526 |
+
min-height: 150px;
|
527 |
+
}
|
528 |
+
|
529 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholders {
|
530 |
+
margin: 10px 0 0 0;
|
531 |
+
}
|
532 |
+
|
533 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder {
|
534 |
+
font-size: 90%;
|
535 |
+
}
|
536 |
+
|
537 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder-separator {
|
538 |
+
margin-top: 10px;;
|
539 |
+
}
|
540 |
+
|
541 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder .placeholder-code {
|
542 |
+
font-family: monospace;
|
543 |
+
font-weight: bold;
|
544 |
+
}
|
545 |
+
|
546 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder .placeholder-description {
|
547 |
+
font-style: italic;
|
548 |
+
}
|
549 |
+
|
550 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons {
|
551 |
+
margin: 30px 0 0 0;
|
552 |
+
text-align: right;
|
553 |
+
}
|
554 |
+
|
555 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons .preview-email {
|
556 |
+
float: left;
|
557 |
+
}
|
558 |
+
|
559 |
+
#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons .cancel {
|
560 |
+
margin-right: 10px;
|
561 |
+
}
|
562 |
+
|
563 |
+
/* Listing metabox - Transactions. */
|
564 |
+
#listing-metabox-transactions table.payments-list {
|
565 |
+
width: 100%;
|
566 |
+
border-spacing: 0;
|
567 |
+
}
|
568 |
+
|
569 |
+
#listing-metabox-transactions table.payments-list tr.payment td {
|
570 |
+
border-bottom: solid 1px #efefef;
|
571 |
+
padding: 2px 0;
|
572 |
+
}
|
573 |
+
|
574 |
+
#listing-metabox-transactions table.payments-list tr.payment td.status {
|
575 |
+
text-align: right;
|
576 |
+
}
|
577 |
+
|
578 |
+
#listing-metabox-transactions table.payments-list tr.payment.completed td {
|
579 |
+
color: green;
|
580 |
+
}
|
581 |
+
|
582 |
+
#listing-metabox-transactions table.payments-list tr.payment.pending td {
|
583 |
+
color: red;
|
584 |
+
}
|
585 |
+
|
586 |
+
#listing-metabox-transactions table.payments-list tr.payment.rejected td {
|
587 |
+
color: #bbb;
|
588 |
+
}
|
589 |
+
|
590 |
+
#listing-metabox-transactions table.payments-list tr.payment.canceled td {
|
591 |
+
text-decoration: line-through;
|
592 |
+
}
|
593 |
+
|
594 |
+
#listing-metabox-transactions table.payments-list tr.payment a {
|
595 |
+
text-decoration: none;
|
596 |
+
color: inherit;
|
597 |
+
}
|
598 |
+
|
599 |
+
#listing-metabox-transactions table.payments-list tr.payment a:hover {
|
600 |
+
text-decoration: underline;
|
601 |
+
}
|
602 |
+
|
603 |
+
|
604 |
+
/* Payment Details. */
|
605 |
+
.wpbdp-payment-details {
|
606 |
+
}
|
607 |
+
|
608 |
+
.wpbdp-payment-details .tag {
|
609 |
+
float: right;
|
610 |
+
}
|
611 |
+
|
612 |
+
.wpbdp-payment-details .details, .wpbdp-payment-details .invoice, .wpbdp-payment-details .actions {
|
613 |
+
clear: both;
|
614 |
+
margin: 20px 0;
|
615 |
+
}
|
616 |
+
|
617 |
+
.wpbdp-payment-details .details dl dt {
|
618 |
+
font-weight: bold;
|
619 |
+
}
|
620 |
+
|
621 |
+
.wpbdp-payment-details .details dl dd {
|
622 |
+
}
|
623 |
+
|
624 |
+
.wpbdp-payment-details table.wpbdp-payment-items-table {
|
625 |
+
width: 100%;
|
626 |
+
}
|
627 |
+
|
628 |
+
.wpbdp-payment-details table.wpbdp-payment-items-table th {
|
629 |
+
text-transform: uppercase;
|
630 |
+
}
|
631 |
+
|
632 |
+
.wpbdp-payment-details table.wpbdp-payment-items-table td {
|
633 |
+
border-top: 1px solid #bbb;
|
634 |
+
padding: 6px 10px 6px 0;
|
635 |
+
}
|
636 |
+
|
637 |
+
.wpbdp-payment-details .actions a.button-primary {
|
638 |
+
color: #fff !important;
|
639 |
+
}
|
640 |
+
|
641 |
+
/* @group Listing fee change. */
|
642 |
+
.listing-fee-change .fee-selection .fee {
|
643 |
+
padding-bottom: 5px;
|
644 |
+
margin-bottom: 10px;
|
645 |
+
border-bottom: dotted 1px #ccc;
|
646 |
+
opacity: 0.85;
|
647 |
+
}
|
648 |
+
|
649 |
+
.listing-fee-change .fee-selection .fee:hover {
|
650 |
+
opacity: 1.0;
|
651 |
+
}
|
652 |
+
|
653 |
+
.listing-fee-change .fee-selection .fee .details {
|
654 |
+
margin-left: 10px;
|
655 |
+
}
|
656 |
+
|
657 |
+
.listing-fee-change .fee-selection .fee .tag {
|
658 |
+
float: right;
|
659 |
+
}
|
660 |
+
|
661 |
+
.listing-fee-change .fee-selection .fee .choose-this {
|
662 |
+
float: right;
|
663 |
+
}
|
664 |
+
/* @end */
|
665 |
+
|
666 |
+
/* {{{ Drag and Drop. */
|
667 |
+
.wpbdp-drag-handle {
|
668 |
+
background: red;
|
669 |
+
width: 6px;
|
670 |
+
height: 10px;
|
671 |
+
display: inline-block;
|
672 |
+
background: url('drag-handle.png') 0 0;
|
673 |
+
cursor: move;
|
674 |
+
float: left;
|
675 |
+
margin: 5px 5px 0 0;
|
676 |
+
vertical-align: middle;
|
677 |
+
}
|
678 |
+
|
679 |
+
.wpbdp-draggable-highlight {
|
680 |
+
background: #bbb;
|
681 |
+
}
|
682 |
+
|
683 |
+
/* }}} */
|
684 |
+
|
685 |
+
/* {{{ Compatibility check. */
|
686 |
+
|
687 |
+
.wpbdp-module-compat-check .module-info {
|
688 |
+
margin-bottom: 3px;
|
689 |
+
}
|
690 |
+
|
691 |
+
.wpbdp-module-compat-check .module-info .module-version, .wpbdp-module-compat-check .module-info .module-required {
|
692 |
+
color: #666;
|
693 |
+
}
|
694 |
+
|
695 |
+
.wpbdp-module-compat-check .module-info .module-version {
|
696 |
+
margin-left: 15px;
|
697 |
+
}
|
698 |
+
|
699 |
+
.wpbdp-module-compat-check .module-info .module-version b {
|
700 |
+
color: #333;
|
701 |
+
}
|
702 |
+
|
703 |
+
.wpbdp-module-compat-check .module-info .module-required b {
|
704 |
+
color: #900000;
|
705 |
+
}
|
706 |
+
|
707 |
+
/* }}} */
|
708 |
+
|
709 |
+
/* {{{ Admin main page. */
|
710 |
+
.toplevel_page_wpbdp_admin .welcome-message {
|
711 |
+
padding: 10px;
|
712 |
+
font-size: 105%;
|
713 |
+
}
|
714 |
+
|
715 |
+
.toplevel_page_wpbdp_admin .welcome-message p {
|
716 |
+
font-size: inherit;
|
717 |
+
}
|
718 |
+
|
719 |
+
.toplevel_page_wpbdp_admin .welcome-message h4 {
|
720 |
+
font-size: 120%;
|
721 |
+
}
|
722 |
+
|
723 |
+
.toplevel_page_wpbdp_admin .welcome-message ul {
|
724 |
+
list-style-position: inside;
|
725 |
+
list-style-type: disc;
|
726 |
+
}
|
727 |
+
|
728 |
+
.toplevel_page_wpbdp_admin ul.shortcuts {
|
729 |
+
margin: auto;
|
730 |
+
}
|
731 |
+
|
732 |
+
.toplevel_page_wpbdp_admin ul.shortcuts li {
|
733 |
+
float: left;
|
734 |
+
margin-right: 10px;
|
735 |
+
}
|
736 |
+
|
737 |
+
.toplevel_page_wpbdp_admin ul.shortcuts li.clear {
|
738 |
+
margin: 0;
|
739 |
+
}
|
740 |
+
/* }}} */
|
741 |
+
|
742 |
+
/* {{ Uninstall. */
|
743 |
+
#wpbdp-uninstall-capture-form .reasons {
|
744 |
+
margin-left: 15px;
|
745 |
+
}
|
746 |
+
|
747 |
+
#wpbdp-uninstall-capture-form .reasons .reason {
|
748 |
+
margin-bottom: 5px;
|
749 |
+
}
|
750 |
+
|
751 |
+
#wpbdp-uninstall-capture-form textarea {
|
752 |
+
margin: 10px 0 0 0;
|
753 |
+
width: 50%;
|
754 |
+
min-height: 100px;
|
755 |
+
display: none;
|
756 |
+
}
|
757 |
+
/* }} */
|
758 |
+
|
759 |
+
.wpbdp-license-expired-warning .module-name {
|
760 |
+
background: #fff9aa;
|
761 |
+
padding: 0 5px;
|
762 |
+
color: #000;
|
763 |
+
}
|
764 |
+
|
765 |
+
.wpbdp-license-expired-warning .dismiss {
|
766 |
+
margin-right: 10px;
|
767 |
+
}
|
768 |
+
|
769 |
+
/* {{ Widget config. */
|
770 |
+
.wp-admin.widgets-php .widget-content span.help {
|
771 |
+
color: #666;
|
772 |
+
}
|
773 |
+
/* }} */
|
admin/resources/admin.js
ADDED
@@ -0,0 +1,730 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var WPBDP_associations_fieldtypes = {};
|
2 |
+
|
3 |
+
(function($) {
|
4 |
+
|
5 |
+
/* Form Fields */
|
6 |
+
var WPBDPAdmin_FormFields = {
|
7 |
+
$f_association: null,
|
8 |
+
$f_fieldtype: null,
|
9 |
+
|
10 |
+
init: function() {
|
11 |
+
WPBDPAdmin_FormFields.$f_association = $('form#wpbdp-formfield-form select#field-association');
|
12 |
+
WPBDPAdmin_FormFields.$f_association.change( WPBDPAdmin_FormFields.onAssociationChange );
|
13 |
+
|
14 |
+
WPBDPAdmin_FormFields.$f_fieldtype = $('form#wpbdp-formfield-form select#field-type');
|
15 |
+
WPBDPAdmin_FormFields.$f_fieldtype.change( WPBDPAdmin_FormFields.onFieldTypeChange );
|
16 |
+
|
17 |
+
$('table.formfields tbody').sortable({
|
18 |
+
placeholder: 'wpbdp-draggable-highlight',
|
19 |
+
handle: '.wpbdp-drag-handle',
|
20 |
+
axis: 'y',
|
21 |
+
cursor: 'move',
|
22 |
+
opacity: 0.9,
|
23 |
+
update: function( event, ui ) {
|
24 |
+
var sorted_items = [];
|
25 |
+
$( this ).find( '.wpbdp-drag-handle' ).each( function( i, v ) {
|
26 |
+
sorted_items.push( $( v ).attr('data-field-id') );
|
27 |
+
} );
|
28 |
+
|
29 |
+
if ( sorted_items )
|
30 |
+
$.post( ajaxurl, { 'action': 'wpbdp-formfields-reorder', 'order': sorted_items } );
|
31 |
+
}
|
32 |
+
});
|
33 |
+
},
|
34 |
+
|
35 |
+
onFieldTypeChange: function() {
|
36 |
+
var $field_type = $(this).find('option:selected');
|
37 |
+
|
38 |
+
if ( !$field_type.length )
|
39 |
+
return;
|
40 |
+
|
41 |
+
var field_type = $field_type.val();
|
42 |
+
|
43 |
+
var request_data = {
|
44 |
+
action: "wpbdp-renderfieldsettings",
|
45 |
+
association: WPBDPAdmin_FormFields.$f_association.find('option:selected').val(),
|
46 |
+
field_type: field_type,
|
47 |
+
field_id: $('#wpbdp-formfield-form input[name="field[id]"]').val()
|
48 |
+
};
|
49 |
+
|
50 |
+
$.post( ajaxurl, request_data, function(response) {
|
51 |
+
if ( response.ok && response.html ) {
|
52 |
+
$('#wpbdp-fieldsettings-html').html(response.html);
|
53 |
+
$('#wpbdp-fieldsettings').show();
|
54 |
+
} else {
|
55 |
+
$('#wpbdp-fieldsettings-html').empty();
|
56 |
+
$('#wpbdp-fieldsettings').hide();
|
57 |
+
}
|
58 |
+
}, 'json' );
|
59 |
+
},
|
60 |
+
|
61 |
+
onAssociationChange: function() {
|
62 |
+
$f_fieldtype = WPBDPAdmin_FormFields.$f_fieldtype;
|
63 |
+
|
64 |
+
var association = $(this).find('option:selected').val();
|
65 |
+
var valid_types = WPBDP_associations_fieldtypes[ association ];
|
66 |
+
|
67 |
+
$f_fieldtype.find('option').removeAttr('disabled');
|
68 |
+
|
69 |
+
$f_fieldtype.find('option').each(function(i,v){
|
70 |
+
if ( $.inArray( $(v).val(), valid_types ) < 0 ) {
|
71 |
+
$(v).attr('disabled', 'disabled');
|
72 |
+
}
|
73 |
+
});
|
74 |
+
|
75 |
+
if ( $f_fieldtype.find('option:selected').attr('disabled') == 'disabled' ) {
|
76 |
+
$f_fieldtype.find('option').removeAttr('selected');
|
77 |
+
$f_fieldtype.find('option[value="' + valid_types[0] + '"]').attr('selected', 'selected');
|
78 |
+
}
|
79 |
+
}
|
80 |
+
};
|
81 |
+
|
82 |
+
|
83 |
+
$(document).ready(function(){
|
84 |
+
WPBDPAdmin_FormFields.init();
|
85 |
+
});
|
86 |
+
|
87 |
+
})(jQuery);
|
88 |
+
|
89 |
+
|
90 |
+
jQuery(document).ready(function($){
|
91 |
+
|
92 |
+
// {{ Manage Fees.
|
93 |
+
$('form#wpbdp-fee-form input[name="_days"]').change(function(){
|
94 |
+
var value = $(this).val();
|
95 |
+
|
96 |
+
// alert(value);
|
97 |
+
|
98 |
+
if (value == 0) {
|
99 |
+
$('form input#wpbdp-fee-form-days-n').attr('disabled', true);
|
100 |
+
$('form input[name="fee[days]"]').val('0');
|
101 |
+
} else {
|
102 |
+
$('form input#wpbdp-fee-form-days-n').removeAttr('disabled');
|
103 |
+
$('form input[name="fee[days]"]').val($('form input#wpbdp-fee-form-days-n').val());
|
104 |
+
$('form input#wpbdp-fee-form-days-n').focus();
|
105 |
+
}
|
106 |
+
|
107 |
+
return true;
|
108 |
+
});
|
109 |
+
|
110 |
+
$('.wpbdp-page-admin-fees .wp-list-table.fees tbody').sortable({
|
111 |
+
placeholder: 'wpbdp-draggable-highlight',
|
112 |
+
handle: '.wpbdp-drag-handle',
|
113 |
+
axis: 'y',
|
114 |
+
cursor: 'move',
|
115 |
+
opacity: 0.9,
|
116 |
+
update: function( event, ui ) {
|
117 |
+
var sorted_items = [];
|
118 |
+
$( this ).find( '.wpbdp-drag-handle' ).each( function( i, v ) {
|
119 |
+
sorted_items.push( $( v ).attr('data-fee-id') );
|
120 |
+
} );
|
121 |
+
|
122 |
+
if ( sorted_items )
|
123 |
+
$.post( ajaxurl, { 'action': 'wpbdp-admin-fees-reorder', 'order': sorted_items } );
|
124 |
+
}
|
125 |
+
});
|
126 |
+
|
127 |
+
$('form#wpbdp-fee-form').submit(function(){
|
128 |
+
// alert($('form#wpbdp-fee-form input[name="fee[days]"]').val());
|
129 |
+
// return false;
|
130 |
+
$('form input[name="fee[days]"]').removeAttr('disabled');
|
131 |
+
return true;
|
132 |
+
});
|
133 |
+
|
134 |
+
$( 'select[name="fee_order[method]"], select[name="fee_order[order]"]' ).change(function(e) {
|
135 |
+
$.ajax({
|
136 |
+
url: ajaxurl,
|
137 |
+
data: $(this).parent('form').serialize(),
|
138 |
+
dataType: 'json',
|
139 |
+
type: 'POST',
|
140 |
+
success: function(res) {
|
141 |
+
if ( res.success )
|
142 |
+
location.reload();
|
143 |
+
}
|
144 |
+
});
|
145 |
+
});
|
146 |
+
|
147 |
+
if ( 'custom' == $('select[name="fee_order[method]"]').val() ) {
|
148 |
+
$( '.wpbdp-page-admin-fees .wp-list-table .wpbdp-drag-handle' ).show();
|
149 |
+
}
|
150 |
+
// }}
|
151 |
+
|
152 |
+
|
153 |
+
/* Listing Info Metabox */
|
154 |
+
|
155 |
+
$('#BusinessDirectory_listinginfo .listing-metabox-tabs a').click(function(e){
|
156 |
+
e.preventDefault();
|
157 |
+
|
158 |
+
var href = $(this).attr('href');
|
159 |
+
|
160 |
+
var $selected = $(this).parent('li').siblings('.selected');
|
161 |
+
|
162 |
+
if ($selected.length > 0) {
|
163 |
+
if ($selected.find('a:first').attr('href') == href) {
|
164 |
+
return;
|
165 |
+
} else {
|
166 |
+
// hide current tab (if any)
|
167 |
+
$selected.removeClass('selected');
|
168 |
+
$($selected.find('a:first').attr('href')).hide();
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
// show new tab
|
173 |
+
$(this).parent('li').addClass('selected');
|
174 |
+
$(href).show();
|
175 |
+
$('.listing-fee-expiration-datepicker').hide();
|
176 |
+
});
|
177 |
+
|
178 |
+
$('#BusinessDirectory_listinginfo .listing-metabox-tabs li.selected a').click();
|
179 |
+
|
180 |
+
|
181 |
+
/* Listing info metabox / fees */
|
182 |
+
|
183 |
+
$('#listing-metabox-fees a.assignfee-link').click(function(e){
|
184 |
+
e.preventDefault();
|
185 |
+
$(this).siblings('.assignfee').show();
|
186 |
+
});
|
187 |
+
|
188 |
+
$('#listing-metabox-fees .assignfee .close-handle').click(function(e){
|
189 |
+
e.preventDefault();
|
190 |
+
$(this).parent('.assignfee').hide();
|
191 |
+
});
|
192 |
+
|
193 |
+
/* Ajax placeholders */
|
194 |
+
|
195 |
+
$('.wpbdp-ajax-placeholder').each(function(i,v){
|
196 |
+
wpbdp_load_placeholder($(v));
|
197 |
+
});
|
198 |
+
|
199 |
+
/*
|
200 |
+
* Admin bulk actions
|
201 |
+
*/
|
202 |
+
|
203 |
+
$('input#doaction, input#doaction2').click(function(e) {
|
204 |
+
var action_name = ( 'doaction' == $(this).attr('id') ) ? 'action' : 'action2';
|
205 |
+
var $selected_option = $('select[name="' + action_name + '"] option:selected');
|
206 |
+
var action_val = $selected_option.val();
|
207 |
+
|
208 |
+
if (action_val.split('-')[0] == 'listing') {
|
209 |
+
var action = action_val.split('-')[1];
|
210 |
+
|
211 |
+
if (action != 'sep0' && action != 'sep1' && action != 'sep2') {
|
212 |
+
var $checked_posts = $('input[name="post[]"]:checked');
|
213 |
+
var uri = $selected_option.attr('data-uri');
|
214 |
+
|
215 |
+
$checked_posts.each(function(i,v){
|
216 |
+
uri += '&post[]=' + $(v).val();
|
217 |
+
});
|
218 |
+
|
219 |
+
window.location.href = uri;
|
220 |
+
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
return true;
|
226 |
+
});
|
227 |
+
|
228 |
+
/* Form fields form preview */
|
229 |
+
$('.wpbdp-admin.wpbdp-page-formfields-preview form input[type="submit"]').click(function(e){
|
230 |
+
e.preventDefault();
|
231 |
+
alert('This form is just a preview. It doesn\'t work.');
|
232 |
+
});
|
233 |
+
|
234 |
+
/* CSV import */
|
235 |
+
$('form#wpbdp-csv-import-form input.assign-listings-to-user').change(function(e){
|
236 |
+
if ( $(this).is(':checked') ) {
|
237 |
+
$('form#wpbdp-csv-import-form .default-user-selection').show();
|
238 |
+
//$('form#wpbdp-csv-import-form select.default-user').hide('disabled');
|
239 |
+
} else {
|
240 |
+
$('form#wpbdp-csv-import-form .default-user-selection').hide();
|
241 |
+
//$('form#wpbdp-csv-import-form select.default-user').attr('disabled', 'disabled');
|
242 |
+
}
|
243 |
+
|
244 |
+
}).change();
|
245 |
+
|
246 |
+
/* Debug info page */
|
247 |
+
$('#wpbdp-admin-debug-info-page a.nav-tab').click(function(e){
|
248 |
+
e.preventDefault();
|
249 |
+
|
250 |
+
$('#wpbdp-admin-debug-info-page a.nav-tab').not(this).removeClass('nav-tab-active');
|
251 |
+
|
252 |
+
var $selected_tab = $(this);
|
253 |
+
$selected_tab.addClass( 'nav-tab-active' );
|
254 |
+
|
255 |
+
$( '.wpbdp-debug-section' ).hide();
|
256 |
+
$( '.wpbdp-debug-section[data-id="' + $(this).attr('href') + '"]' ).show();
|
257 |
+
});
|
258 |
+
|
259 |
+
if ( $('#wpbdp-admin-debug-info-page a.nav-tab').length > 0 )
|
260 |
+
$('#wpbdp-admin-debug-info-page a.nav-tab').get(0).click();
|
261 |
+
|
262 |
+
/* Transactions */
|
263 |
+
$( '.wpbdp-page-admin-transactions .column-actions a.details-link' ).click(function(e){
|
264 |
+
e.preventDefault();
|
265 |
+
var $tr = $(this).parents('tr');
|
266 |
+
var $details = $tr.find('div.more-details');
|
267 |
+
|
268 |
+
var $tr_details = $tr.next('tr.more-details-row');
|
269 |
+
if ( $tr_details.length > 0 ) {
|
270 |
+
$tr_details.remove();
|
271 |
+
$(this).text( $(this).text().replace( '-', '+' ) );
|
272 |
+
return;
|
273 |
+
} else {
|
274 |
+
$(this).text( $(this).text().replace( '+', '-' ) );
|
275 |
+
}
|
276 |
+
|
277 |
+
$tr.after( '<tr class="more-details-row"><td colspan="7">' + $details.html() + '</td></tr>' ).show();
|
278 |
+
});
|
279 |
+
|
280 |
+
});
|
281 |
+
|
282 |
+
function wpbdp_load_placeholder($v) {
|
283 |
+
var action = $v.attr('data-action');
|
284 |
+
var post_id = $v.attr('data-post_id');
|
285 |
+
var baseurl = $v.attr('data-baseurl');
|
286 |
+
|
287 |
+
$v.load(ajaxurl, {"action": action, "post_id": post_id, "baseurl": baseurl});
|
288 |
+
}
|
289 |
+
|
290 |
+
|
291 |
+
var WPBDP_Admin = {};
|
292 |
+
WPBDP_Admin.payments = {};
|
293 |
+
WPBDP_Admin.listingMetabox = {};
|
294 |
+
|
295 |
+
// TODO: integrate this into $.
|
296 |
+
WPBDP_Admin.ProgressBar = function($item, settings) {
|
297 |
+
$item.empty();
|
298 |
+
$item.html('<div class="wpbdp-progress-bar"><span class="progress-text">0%</span><div class="progress-bar"><div class="progress-bar-outer"><div class="progress-bar-inner" style="width: 0%;"></div></div></div>');
|
299 |
+
|
300 |
+
this.$item = $item;
|
301 |
+
this.$text = $item.find('.progress-text');
|
302 |
+
this.$bar = $item.find('.progress-bar');
|
303 |
+
|
304 |
+
this.set = function( completed, total ) {
|
305 |
+
var pcg = Math.round( 100 * parseInt( completed) / parseInt( total ) );
|
306 |
+
this.$text.text(pcg + '%');
|
307 |
+
this.$bar.find('.progress-bar-inner').attr('style', 'width: ' + pcg + '%;');
|
308 |
+
};
|
309 |
+
};
|
310 |
+
|
311 |
+
(function($) {
|
312 |
+
WPBDP_Admin.dialog = {};
|
313 |
+
var dialog = WPBDP_Admin.dialog;
|
314 |
+
|
315 |
+
// if ($('#wpbdp-modal-dialog').length == 0) {
|
316 |
+
// $('body').append($('<div id="wpbdp-modal-dialog"></div>'));
|
317 |
+
// }
|
318 |
+
})(jQuery);
|
319 |
+
|
320 |
+
|
321 |
+
|
322 |
+
(function($) {
|
323 |
+
var payments = WPBDP_Admin.payments;
|
324 |
+
|
325 |
+
payments._initialize = function() {
|
326 |
+
$('#BusinessDirectory_listinginfo a.payment-details-link').click(function(e) {
|
327 |
+
e.preventDefault();
|
328 |
+
payments.viewPaymentDetails( $(this).attr('data-id') );
|
329 |
+
});
|
330 |
+
|
331 |
+
if ($('#wpbdp-modal-dialog').length == 0) {
|
332 |
+
$('body').append($('<div id="wpbdp-modal-dialog"></div>'));
|
333 |
+
}
|
334 |
+
};
|
335 |
+
|
336 |
+
payments.viewPaymentDetails = function(id) {
|
337 |
+
$.get( ajaxurl, { 'action': 'wpbdp-payment-details', 'id': id }, function(res) {
|
338 |
+
if (res && res.success) {
|
339 |
+
if ($('#wpbdp-modal-dialog').length == 0) {
|
340 |
+
$('body').append($('<div id="wpbdp-modal-dialog"></div>'));
|
341 |
+
}
|
342 |
+
|
343 |
+
$('#wpbdp-modal-dialog').html(res.data.html);
|
344 |
+
tb_show('', '#TB_inline?inlineId=wpbdp-modal-dialog');
|
345 |
+
$('#wpbdp-modal-dialog').remove();
|
346 |
+
}
|
347 |
+
}, 'json' );
|
348 |
+
};
|
349 |
+
|
350 |
+
// Initialize payments.
|
351 |
+
$(document).ready(function(){ payments._initialize(); });
|
352 |
+
|
353 |
+
})(jQuery);
|
354 |
+
|
355 |
+
(function($) {
|
356 |
+
var metabox = WPBDP_Admin.listingMetabox;
|
357 |
+
|
358 |
+
metabox._initialize = function() {
|
359 |
+
// Expiration date changing.
|
360 |
+
$('#listing-metabox-generalinfo, #listing-metabox-fees').each(function(i, v) {
|
361 |
+
var $tab = $(v);
|
362 |
+
$tab.find('.expiration-date-info .datepicker').each(function(i, v) {
|
363 |
+
var $dp = $(v);
|
364 |
+
var $changeLink = $dp.siblings('a.expiration-change-link');
|
365 |
+
|
366 |
+
$dp.hide().datepicker({
|
367 |
+
dateFormat: 'yy-mm-dd',
|
368 |
+
defaultDate: $changeLink.attr('data-date'),
|
369 |
+
onSelect: function(newDate) {
|
370 |
+
if (newDate) {
|
371 |
+
var $expirationDate = $(this).siblings('.expiration-date');
|
372 |
+
var $spinner = $(this).parents('.listing-category').find('.spinner:first');
|
373 |
+
|
374 |
+
$expirationDate.text('--'); $spinner.show();
|
375 |
+
|
376 |
+
$.post(ajaxurl, {action: 'wpbdp-listing_set_expiration', renewal_id: $changeLink.attr('data-renewal_id'), expiration_date: newDate}, function(res) {
|
377 |
+
if (res && res.success)
|
378 |
+
$spinner.hide();
|
379 |
+
$expirationDate.text(res.data.formattedExpirationDate).show();
|
380 |
+
}, 'json');
|
381 |
+
}
|
382 |
+
|
383 |
+
$(this).hide();
|
384 |
+
|
385 |
+
}
|
386 |
+
});
|
387 |
+
});
|
388 |
+
|
389 |
+
$tab.find('a.expiration-change-link').click(function(e) {
|
390 |
+
e.preventDefault();
|
391 |
+
|
392 |
+
var renewal_id = $(this).attr('data-renewal_id');
|
393 |
+
$('.expiration-date-info .datepicker').not('.renewal-' + renewal_id ).hide();
|
394 |
+
$('.expiration-date-info .datepicker.renewal-' + renewal_id).toggle();
|
395 |
+
});
|
396 |
+
});
|
397 |
+
|
398 |
+
// Listing category deletion.
|
399 |
+
$('.listing-category a.category-delete').click(function(e) {
|
400 |
+
e.preventDefault();
|
401 |
+
|
402 |
+
var listingID = $(this).attr('data-listing');
|
403 |
+
var categoryID = $(this).attr('data-category');
|
404 |
+
|
405 |
+
if ( !listingID || !categoryID ) {
|
406 |
+
return;
|
407 |
+
}
|
408 |
+
|
409 |
+
var $category = $('.listing-category-' + categoryID);
|
410 |
+
$.post(ajaxurl, {action: 'wpbdp-listing_remove_category', 'listing': listingID, 'category': categoryID}, function(res) {
|
411 |
+
if (res && res.success) {
|
412 |
+
$('input[name="tax_input[wpbdp_category][]"][value="' + categoryID + '"]').attr('checked', false);
|
413 |
+
$category.fadeOut(function(){ $(this).remove(); });
|
414 |
+
}
|
415 |
+
}, 'json');
|
416 |
+
});
|
417 |
+
|
418 |
+
// Listing category fee change.
|
419 |
+
$('.listing-category a.category-change-fee').click(function(e) {
|
420 |
+
e.preventDefault();
|
421 |
+
|
422 |
+
if ($('#wpbdp-modal-dialog').length == 0) {
|
423 |
+
$('body').append($('<div id="wpbdp-modal-dialog"></div>'));
|
424 |
+
}
|
425 |
+
|
426 |
+
$.post(ajaxurl, {'action': 'wpbdp-listing_change_fee', 'renewal': $(this).attr('data-renewal')}, function(res) {
|
427 |
+
if (res && res.success) {
|
428 |
+
$('#wpbdp-modal-dialog').html(res.data.html);
|
429 |
+
tb_show('', '#TB_inline?inlineId=wpbdp-modal-dialog');
|
430 |
+
$('#wpbdp-modal-dialog').remove();
|
431 |
+
}
|
432 |
+
}, 'json');
|
433 |
+
});
|
434 |
+
};
|
435 |
+
|
436 |
+
$(document).ready(function(){
|
437 |
+
if ( $('#listing-metabox-fees').length > 0 ) {
|
438 |
+
metabox._initialize();
|
439 |
+
}
|
440 |
+
});
|
441 |
+
|
442 |
+
})(jQuery);
|
443 |
+
|
444 |
+
/* {{ Settings. */
|
445 |
+
(function($) {
|
446 |
+
var s = WPBDP_Admin.settings = {
|
447 |
+
_whenTrueActivateChilds: {},
|
448 |
+
|
449 |
+
init: function() {
|
450 |
+
var t = this;
|
451 |
+
|
452 |
+
// E-mail template editors.
|
453 |
+
$( '.wpbdp-settings-email' ).each(function(i, v) {
|
454 |
+
var $email = $(v);
|
455 |
+
var $preview = $email.find('.short-preview');
|
456 |
+
var $editor = $email.find('.editor');
|
457 |
+
var $subject = $editor.find('.subject-text');
|
458 |
+
var $body = $editor.find('.body-text');
|
459 |
+
var data = {'subject': '', 'body': ''};
|
460 |
+
|
461 |
+
$preview.click(function(e) {
|
462 |
+
data['subject'] = $subject.val();
|
463 |
+
data['body'] = $body.val();
|
464 |
+
|
465 |
+
$preview.hide();
|
466 |
+
$editor.show();
|
467 |
+
});
|
468 |
+
|
469 |
+
$( '.cancel', $editor ).click(function(e) {
|
470 |
+
e.preventDefault();
|
471 |
+
|
472 |
+
$subject.val(data['subject']);
|
473 |
+
$body.val(data['body']);
|
474 |
+
|
475 |
+
$editor.hide();
|
476 |
+
$preview.show();
|
477 |
+
});
|
478 |
+
|
479 |
+
$( '.save', $editor ).click(function(e) {
|
480 |
+
e.preventDefault();
|
481 |
+
$('form#wpbdp-admin-settings #submit').click();
|
482 |
+
});
|
483 |
+
|
484 |
+
$( '.preview-email', $editor ).click(function(e) {
|
485 |
+
e.preventDefault();
|
486 |
+
|
487 |
+
var subject = $subject.val();
|
488 |
+
var body = $body.val();
|
489 |
+
|
490 |
+
$.ajax({
|
491 |
+
url: ajaxurl,
|
492 |
+
data: { 'action': 'wpbdp-admin-settings-email-preview',
|
493 |
+
'nonce': $editor.attr('data-preview-nonce'),
|
494 |
+
'setting': $email.attr('data-setting'),
|
495 |
+
'subject': subject,
|
496 |
+
'body': body },
|
497 |
+
dataType: 'json',
|
498 |
+
type: 'POST',
|
499 |
+
success: function(res) {
|
500 |
+
if ( ! res.success ) {
|
501 |
+
return;
|
502 |
+
}
|
503 |
+
|
504 |
+
if ( 0 == $( '#wpbdp-modal-dialog' ).length )
|
505 |
+
$( 'body' ).append( '<div id="wpbdp-modal-dialog" style="display: none;"></div>' );
|
506 |
+
|
507 |
+
$( '#wpbdp-modal-dialog' ).html(res.data.html);
|
508 |
+
tb_show( '', '#TB_inline?inlineId=wpbdp-modal-dialog' );
|
509 |
+
$( '#wpbdp-modal-dialog' ).remove();
|
510 |
+
}
|
511 |
+
});
|
512 |
+
|
513 |
+
});
|
514 |
+
|
515 |
+
});
|
516 |
+
|
517 |
+
$('select#quick-search-fields').change(function() {
|
518 |
+
var selected = $(this).find( 'option.textfield:selected' ).length;
|
519 |
+
|
520 |
+
if ( selected > 0 ) {
|
521 |
+
$('span.text-fields-warning').fadeIn('fast');
|
522 |
+
} else {
|
523 |
+
$('span.text-fields-warning').fadeOut('fast');
|
524 |
+
}
|
525 |
+
});
|
526 |
+
|
527 |
+
$.each( this._whenTrueActivateChilds, function( p, chs ) {
|
528 |
+
$('input[name="wpbdp-' + p + '"]').change(function(e) {
|
529 |
+
t.handleToggle( p );
|
530 |
+
});
|
531 |
+
|
532 |
+
t.handleToggle( p );
|
533 |
+
} );
|
534 |
+
},
|
535 |
+
|
536 |
+
handleToggle: function( setting ) {
|
537 |
+
var childs = this._whenTrueActivateChilds[ setting ];
|
538 |
+
|
539 |
+
if ( 'undefined' === typeof( childs ) )
|
540 |
+
return;
|
541 |
+
|
542 |
+
var checked = $( 'input[name="wpbdp-' + setting + '"]').is(':checked');
|
543 |
+
|
544 |
+
$.each( this._whenTrueActivateChilds[ setting ], function( i, c ) {
|
545 |
+
var $c = $( '[name="wpbdp-' + c + '"], [name="wpbdp-' + c + '[]"]' );
|
546 |
+
var $row = $c.parents( 'tr' );
|
547 |
+
|
548 |
+
// FIXME: 'disabled' fields result in the setting being "cleared" in the backend. Why?
|
549 |
+
if ( checked ) {
|
550 |
+
// $c.removeAttr( 'disabled' );
|
551 |
+
$c.removeAttr( 'contenteditable' );
|
552 |
+
$row.removeClass('disabled');
|
553 |
+
} else {
|
554 |
+
// $c.attr( 'disabled', 'disabled' );
|
555 |
+
$c.attr( 'contenteditable', 'false' );
|
556 |
+
$row.addClass('disabled');
|
557 |
+
}
|
558 |
+
} );
|
559 |
+
},
|
560 |
+
|
561 |
+
add_requirement: function( setting, parent_, req ) {
|
562 |
+
if ( 'undefined' === typeof this._whenTrueActivateChilds[ parent_ ] )
|
563 |
+
this._whenTrueActivateChilds[ parent_ ] = [];
|
564 |
+
|
565 |
+
this._whenTrueActivateChilds[ parent_ ].push( setting );
|
566 |
+
}
|
567 |
+
};
|
568 |
+
|
569 |
+
$(document).ready(function(){
|
570 |
+
if ( 0 == $('body.directory-admin_page_wpbdp_admin_settings').length )
|
571 |
+
return;
|
572 |
+
|
573 |
+
s.init();
|
574 |
+
});
|
575 |
+
})(jQuery);
|
576 |
+
/* }} */
|
577 |
+
|
578 |
+
/* {{ Uninstall. */
|
579 |
+
(function($) {
|
580 |
+
var u = WPBDP_Admin.uninstall = {
|
581 |
+
init: function() {
|
582 |
+
$( 'form#wpbdp-uninstall-capture-form input[name="uninstall[reason_id]"]' ).change(function(e) {
|
583 |
+
var val = $(this).val();
|
584 |
+
|
585 |
+
if ( '0' == val ) {
|
586 |
+
$( 'form#wpbdp-uninstall-capture-form textarea[name="uninstall[reason_text]"]' ).fadeIn();
|
587 |
+
} else {
|
588 |
+
$( 'form#wpbdp-uninstall-capture-form textarea[name="uninstall[reason_text]"]' ).fadeOut( 'fast', function() {
|
589 |
+
$(this).val('');
|
590 |
+
} );
|
591 |
+
}
|
592 |
+
});
|
593 |
+
}
|
594 |
+
};
|
595 |
+
|
596 |
+
$(document).ready(function(){
|
597 |
+
if ( $( 'body.directory-admin_page_wpbdp_uninstall' ).length > 0 )
|
598 |
+
u.init();
|
599 |
+
});
|
600 |
+
})(jQuery);
|
601 |
+
/* }} */
|
602 |
+
|
603 |
+
// {{ Widgets.
|
604 |
+
(function($) {
|
605 |
+
$(document).ready(function() {
|
606 |
+
if ( $('body.wp-admin.widgets-php').length == 0 ) {
|
607 |
+
return;
|
608 |
+
}
|
609 |
+
|
610 |
+
$( 'input.wpbdp-toggle-images' ).change(function() {
|
611 |
+
var checked = $(this).is(':checked');
|
612 |
+
|
613 |
+
if ( checked ) {
|
614 |
+
$(this).parents('.widget').find('.thumbnail-width-config, .thumbnail-height-config').fadeIn('fast');
|
615 |
+
} else {
|
616 |
+
$(this).parents('.widget').find('.thumbnail-width-config, .thumbnail-height-config').fadeOut('fast');
|
617 |
+
}
|
618 |
+
});
|
619 |
+
|
620 |
+
});
|
621 |
+
})(jQuery);
|
622 |
+
// }}
|
623 |
+
|
624 |
+
// {{ Create main page warning.
|
625 |
+
(function($) {
|
626 |
+
$(document).ready(function() {
|
627 |
+
$( 'a.wpbdp-create-main-page-button' ).click(function(e) {
|
628 |
+
e.preventDefault();
|
629 |
+
var $msg = $(this).parents('div.error');
|
630 |
+
|
631 |
+
$.ajax({
|
632 |
+
'url': ajaxurl,
|
633 |
+
'data': { 'action': 'wpbdp-create-main-page',
|
634 |
+
'_wpnonce': $(this).attr('data-nonce') },
|
635 |
+
'dataType': 'json',
|
636 |
+
success: function(res) {
|
637 |
+
if ( ! res.success )
|
638 |
+
return;
|
639 |
+
|
640 |
+
$msg.fadeOut( 'fast', function() {
|
641 |
+
$(this).html( '<p>' + res.message + '</p>' )
|
642 |
+
$(this).removeClass('error')
|
643 |
+
$(this).addClass('updated')
|
644 |
+
$(this).fadeIn( 'fast' );
|
645 |
+
} );
|
646 |
+
}
|
647 |
+
});
|
648 |
+
});
|
649 |
+
});
|
650 |
+
})(jQuery);
|
651 |
+
// }}
|
652 |
+
|
653 |
+
// {{ Settings - License Activation.
|
654 |
+
(function($) {
|
655 |
+
var l = WPBDP_Admin.licensing = {
|
656 |
+
init: function() {
|
657 |
+
$( 'input.license-activate' ).click(function(){
|
658 |
+
var module = $(this).parent( '.license-activation' ).attr( 'data-module-id' );
|
659 |
+
var license = $( 'input[type="text"]#license-key-' + module ).val();
|
660 |
+
l.activation_change( module, license, 'activate' );
|
661 |
+
});
|
662 |
+
|
663 |
+
$( 'input.license-deactivate' ).click(function(){
|
664 |
+
var module = $(this).parent( '.license-activation' ).attr( 'data-module-id' );
|
665 |
+
var license = $( 'input[type="text"]#license-key-' + module );
|
666 |
+
l.activation_change( module, '', 'deactivate' );
|
667 |
+
});
|
668 |
+
},
|
669 |
+
|
670 |
+
activation_change: function(module, license, action) {
|
671 |
+
var $container = $( '.license-activation[data-module-id="' + module + '"]' );
|
672 |
+
var $msg = $( '.status-message', $container );
|
673 |
+
var nonce = $( 'input[name="nonce"]', $container ).val();
|
674 |
+
|
675 |
+
$msg.removeClass('ok error');
|
676 |
+
|
677 |
+
$msg.html( $( 'input.license-' + action, $container ).attr('data-L10n') );
|
678 |
+
|
679 |
+
$.post( ajaxurl, { 'action': 'wpbdp-' + action + '-license', 'module': module, 'key': license, 'nonce': nonce }, function(res) {
|
680 |
+
if ( res.success ) {
|
681 |
+
$msg.hide()
|
682 |
+
.html(res.message)
|
683 |
+
.removeClass('error')
|
684 |
+
.addClass('ok')
|
685 |
+
.show();
|
686 |
+
|
687 |
+
$('input.license-' + action, $container).hide();
|
688 |
+
$('input[type="button"]', $container).not( '.license-' + action ).show();
|
689 |
+
|
690 |
+
if ( 'activate' == action )
|
691 |
+
$( 'input[type="text"]#license-key-' + module ).attr('readonly', 'readonly');
|
692 |
+
else
|
693 |
+
$( 'input[type="text"]#license-key-' + module ).removeAttr('readonly');
|
694 |
+
} else {
|
695 |
+
$msg.hide()
|
696 |
+
.html(res.error)
|
697 |
+
.removeClass('ok')
|
698 |
+
.addClass('error')
|
699 |
+
.show();
|
700 |
+
|
701 |
+
if ( 'deactivate' == action )
|
702 |
+
$( 'input[type="text"]#license-key-' + module ).removeAttr('readonly');
|
703 |
+
}
|
704 |
+
}, 'json' );
|
705 |
+
}
|
706 |
+
|
707 |
+
};
|
708 |
+
|
709 |
+
$(document).ready(function() {
|
710 |
+
if ( $( 'input.license-activate, input.license-deactivate' ).length > 0 )
|
711 |
+
l.init();
|
712 |
+
|
713 |
+
if ( $( '.wpbdp-license-expired-warning' ).length > 0 ) {
|
714 |
+
$( '.wpbdp-license-expired-warning .dismiss' ).click(function (e) {
|
715 |
+
e.preventDefault();
|
716 |
+
|
717 |
+
var module_id = $(this).attr('data-module');
|
718 |
+
var nonce = $(this).attr('data-nonce');
|
719 |
+
var $warning = $(this).parents('.wpbdp-license-expired-warning');
|
720 |
+
|
721 |
+
$.post( ajaxurl, {'action': 'wpbdp-license-expired-warning-dismiss', 'nonce': nonce, 'module': module_id}, function(res) {
|
722 |
+
if ( res.success ) {
|
723 |
+
$warning.fadeOut( 'fast' );
|
724 |
+
}
|
725 |
+
}, 'json' );
|
726 |
+
});
|
727 |
+
}
|
728 |
+
});
|
729 |
+
})(jQuery);
|
730 |
+
// }}
|
admin/resources/admin.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.cf:before,.cf:after{content:" ";display:table}.cf:after{clear:both}.cf{*zoom:1}span.tag{background:#444;border-radius:2px;padding:2px 5px;color:#fff;font-size:9px !important;margin-right:2px;text-transform:uppercase;text-decoration:none !important;line-height:1.5 !important}.wpbdp-admin-content.with-sidebar{margin-top:20px;clear:left;float:left;width:78%}.wpbdp-admin .sidebar{margin-top:20px;float:right;clear:right;width:20%}.wpbdp-admin .sidebar .postbox{min-width:0 !important}.wpbdp-admin .sidebar .premium-modules h3 span{color:#145200;font-weight:bold}.wpbdp-admin .sidebar .premium-modules{border-color:#0ead00;border-width:3px;background:#ffffcf}.wpbdp-page-admin-fees .wp-list-table .wpbdp-drag-handle{margin-right:15px;display:none}.wpbdp-page-admin-fees .purchase-gateways{margin-left:20px}.wpbdp-page-admin-fees .purchase-gateways .gateway{float:left;width:35%;margin:30px 20px 0 0}.wpbdp-page-admin-fees .purchase-gateways .gateway.installed{opacity:.5}.wpbdp-page-admin-fees .purchase-gateways .gateway a img.gateway-logo{height:40px;margin:0;padding:0;border:0}.wpbdp-page-admin-fees .purchase-gateways .gateway a.price{margin-top:10px;display:block;color:green;font-size:22px;font-weight:bold}.wpbdp-page-admin-fees .purchase-gateways .gateway .check-mark{font-size:150%;font-weight:bold;color:green}td.column-payment_status .status,td.column-sticky_status .status{background:#444;border-radius:2px;padding:2px 5px;color:#fff;font-size:90%}td.column-payment_status .status.ok{background:green}td.column-payment_status .paymentdata{font-size:85%}td.column-payment_status .paymentdata b{font-weight:normal}td.column-payment_status .paymentdata span{font-style:italic}td.column-sticky_status .status.notpaid{background:orange}td.column-sticky_status .status.pending{background:red;font-weight:bold}td.column-sticky_status .status.sticky{background:green}table.wp-list-table td .tag{background:#444;border-radius:2px;padding:2px 5px;color:#fff;font-size:90%;margin-right:2px}table.wp-list-table.formfields th.column-label{width:40%}table.wp-list-table.formfields th.column-tags,table.wp-list-table.formfields td.column-tags{width:200px}table.wp-list-table.formfields th.column-order,table.wp-list-table.formfields td.column-order{width:55px}table.wp-list-table.formfields td.column-order .wpbdp-drag-handle{visibility:hidden}table.wp-list-table.formfields tr:hover .wpbdp-drag-handle{visibility:visible}table.wp-list-table.formfields .tag.required{background:orange}table.wp-list-table.formfields .tag.in-excerpt{background:green}table.wp-list-table.formfields .tag.in-listing{background:green}table.wp-list-table.formfields tr.wpbdp-draggable-highlight{height:54px}table.wp-list-table.formfields tr.ui-sortable-helper{background:#fff;border:1px dashed #c1c1c1}#wpbdp-listing-fields input[type="text"]{width:70%}#wpbdp-listing-fields .wpbdp-form-field.url .wpbdp-form-field-html{padding-left:10px}#wpbdp-listing-fields .wpbdp-form-field.url input[type="text"]{display:block}#wpbdp-listing-fields #wpbdp-uploaded-images .wpbdp-image{padding:5px;width:150px;vertical-align:top;display:inline-block;zoom:1;*display:inline;min-height:210px;_height:210px}#wpbdp-listing-fields div.listing-images .image img{max-width:150px}ul#wpbusdirmanerrors{margin-left:20px}.wpbdp-csv-import-example{width:100%;padding:10px;display:block;background:#fff;border:solid 1px #ddd;font-size:90%;font-family:monospace;height:100%;white-space:pre}#wpbdp-csv-import-form input[type="file"]{border:0}table.wpbdp-csv-import-results,table.wpbdp-csv-import-warnings{width:100%}table.wpbdp-csv-import-results .line-no,table.wpbdp-csv-import-warnings .line-no{width:50px}table.wpbdp-csv-import-results td.line,table.wpbdp-csv-import-warnings td.line{font-family:monospace;font-size:90%}table.wpbdp-csv-import-results .error,table.wpbdp-csv-import-warnings .error{width:200px}table.wpbdp-csv-import-headers{width:100%}table.wpbdp-csv-import-headers td.field-is-required,table.wpbdp-csv-import-headers td.field-is-multivalued{text-align:center}table.wpbdp-csv-import-headers tbody tr{background:#f9f9f9}table.wpbdp-csv-import-headers tbody tr.alt{background:inherit}.wpbdp-form-field.image .preview{float:none}table.wpbdp-debug-section{width:90%}table.wpbdp-debug-section tbody tr{background:#efefef}table.wpbdp-debug-section tbody tr td{padding:3px 8px}table.wpbdp-debug-section tbody tr:nth-child(2n){background:#f5f5f5}.wpbdp-page-admin-transactions .tag{font-size:95%}.wpbdp-page-admin-transactions .tag.approved{background:green}.wpbdp-page-admin-transactions .tag.pending{background:red}.wpbdp-page-admin-transactions .column-actions a.delete{color:#bc0b0b}.wpbdp-page-admin-transactions tr.more-details-row{background:#fff}.wpbdp-page-admin-transactions tr.more-details-row td{padding-left:40px;font-size:95%}.wpbdp-page-admin-transactions tr.more-details-row td dl dt{font-weight:bold}body.taxonomy-wpbdp_category .column-id{width:35px}.transaction-status-container{text-align:right;padding:5px}.wpbdp-progress-bar .progress-bar{margin-left:10px;display:inline-block;vertical-align:middle}.wpbdp-progress-bar .progress-bar-outer{min-width:200px;height:12px;border:solid 1px #36c;padding:0}.wpbdp-progress-bar .progress-bar-inner{height:100%;background:#9cf}.wpbdp-note{padding:5px 10px;background:#d7f5ff;margin:5px 0 20px 0;border:solid 1px #bad5df;border-radius:4px}.wpbdp-note p{margin:0}.wpbdp-note h1,.wpbdp-note h2,.wpbdp-note h3,.wpbdp-note h4{margin:0 0 8px 0}.directory-admin_page_wpbdp_admin_settings table.form-table th,.directory-admin_page_wpbdp_admin_settings table.form-table td{font-size:13px;line-height:1.0;padding:8px 20px}.directory-admin_page_wpbdp_admin_settings table.form-table th{min-width:150px}.directory-admin_page_wpbdp_admin_settings input,.directory-admin_page_wpbdp_admin_settings select{font-size:13px;line-height:1.0}.directory-admin_page_wpbdp_admin_settings textarea{font-size:13px;width:95%}.directory-admin_page_wpbdp_admin_settings select{display:block}.directory-admin_page_wpbdp_admin_settings .license-activation .status-message{font-size:85%;color:#595959;font-style:italic}.directory-admin_page_wpbdp_admin_settings .license-activation .status-message.ok{color:green}.directory-admin_page_wpbdp_admin_settings .license-activation .status-message.error{color:red}.directory-admin_page_wpbdp_admin_settings .group-error{border-top:solid 1px red}.directory-admin_page_wpbdp_admin_settings .group-warning{border-top:solid 1px yellow}.tag.paymentstatus.ok{background:green}.tag.paymentstatus.completed{background:green}.tag.paymentstatus.pending{background:red}#wpbdp-admin-settings tr.disabled{opacity:.7}#wpbdp-admin-settings .text-fields-warning{font-size:90%;display:block;margin-bottom:2px}#wpbdp-admin-settings .wpbdp-settings-email{margin:5px 0 0 0;border:solid 1px #ccc;padding:5px;background:#fff}#wpbdp-admin-settings .wpbdp-settings-email .short-preview{color:#999;font-size:90%;height:45px;cursor:pointer;overflow:hidden}#wpbdp-admin-settings .wpbdp-settings-email .short-preview h4{margin:0 0 10px 0}#wpbdp-admin-settings .wpbdp-settings-email .short-preview .edit-toggle{float:right}#wpbdp-admin-settings .wpbdp-settings-email .short-preview:hover .edit-toggle{visibility:visible}#wpbdp-admin-settings .wpbdp-settings-email .short-preview dl{margin:0;padding:0}#wpbdp-admin-settings .wpbdp-settings-email .short-preview dt{font-weight:bold;margin:0;padding:0}#wpbdp-admin-settings .wpbdp-settings-email .short-preview dd{margin:0;padding:0 0 0 10px}#wpbdp-admin-settings .wpbdp-settings-email .editor{margin-left:10px;font-size:90%}#wpbdp-admin-settings .wpbdp-settings-email .editor table.form-table{margin:0;padding:0}#wpbdp-admin-settings .wpbdp-settings-email table.form-table th{padding-left:4px;padding-right:0;min-width:0;width:20%}#wpbdp-admin-settings .wpbdp-settings-email .editor input[type="text"]{width:70%}#wpbdp-admin-settings .wpbdp-settings-email .editor textarea{width:100%;min-height:150px}#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholders{margin:10px 0 0 0}#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder{font-size:90%}#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder-separator{margin-top:10px}#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder .placeholder-code{font-family:monospace;font-weight:bold}#wpbdp-admin-settings .wpbdp-settings-email .editor .placeholder .placeholder-description{font-style:italic}#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons{margin:30px 0 0 0;text-align:right}#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons .preview-email{float:left}#wpbdp-admin-settings .wpbdp-settings-email .editor .buttons .cancel{margin-right:10px}#listing-metabox-transactions table.payments-list{width:100%;border-spacing:0}#listing-metabox-transactions table.payments-list tr.payment td{border-bottom:solid 1px #efefef;padding:2px 0}#listing-metabox-transactions table.payments-list tr.payment td.status{text-align:right}#listing-metabox-transactions table.payments-list tr.payment.completed td{color:green}#listing-metabox-transactions table.payments-list tr.payment.pending td{color:red}#listing-metabox-transactions table.payments-list tr.payment.rejected td{color:#bbb}#listing-metabox-transactions table.payments-list tr.payment.canceled td{text-decoration:line-through}#listing-metabox-transactions table.payments-list tr.payment a{text-decoration:none;color:inherit}#listing-metabox-transactions table.payments-list tr.payment a:hover{text-decoration:underline}.wpbdp-payment-details .tag{float:right}.wpbdp-payment-details .details,.wpbdp-payment-details .invoice,.wpbdp-payment-details .actions{clear:both;margin:20px 0}.wpbdp-payment-details .details dl dt{font-weight:bold}.wpbdp-payment-details table.wpbdp-payment-items-table{width:100%}.wpbdp-payment-details table.wpbdp-payment-items-table th{text-transform:uppercase}.wpbdp-payment-details table.wpbdp-payment-items-table td{border-top:1px solid #bbb;padding:6px 10px 6px 0}.wpbdp-payment-details .actions a.button-primary{color:#fff !important}.listing-fee-change .fee-selection .fee{padding-bottom:5px;margin-bottom:10px;border-bottom:dotted 1px #ccc;opacity:.85}.listing-fee-change .fee-selection .fee:hover{opacity:1.0}.listing-fee-change .fee-selection .fee .details{margin-left:10px}.listing-fee-change .fee-selection .fee .tag{float:right}.listing-fee-change .fee-selection .fee .choose-this{float:right}.wpbdp-drag-handle{background:red;width:6px;height:10px;display:inline-block;background:url('drag-handle.png') 0 0;cursor:move;float:left;margin:5px 5px 0 0;vertical-align:middle}.wpbdp-draggable-highlight{background:#bbb}.wpbdp-module-compat-check .module-info{margin-bottom:3px}.wpbdp-module-compat-check .module-info .module-version,.wpbdp-module-compat-check .module-info .module-required{color:#666}.wpbdp-module-compat-check .module-info .module-version{margin-left:15px}.wpbdp-module-compat-check .module-info .module-version b{color:#333}.wpbdp-module-compat-check .module-info .module-required b{color:#900000}.toplevel_page_wpbdp_admin .welcome-message{padding:10px;font-size:105%}.toplevel_page_wpbdp_admin .welcome-message p{font-size:inherit}.toplevel_page_wpbdp_admin .welcome-message h4{font-size:120%}.toplevel_page_wpbdp_admin .welcome-message ul{list-style-position:inside;list-style-type:disc}.toplevel_page_wpbdp_admin ul.shortcuts{margin:auto}.toplevel_page_wpbdp_admin ul.shortcuts li{float:left;margin-right:10px}.toplevel_page_wpbdp_admin ul.shortcuts li.clear{margin:0}#wpbdp-uninstall-capture-form .reasons{margin-left:15px}#wpbdp-uninstall-capture-form .reasons .reason{margin-bottom:5px}#wpbdp-uninstall-capture-form textarea{margin:10px 0 0 0;width:50%;min-height:100px;display:none}.wpbdp-license-expired-warning .module-name{background:#fff9aa;padding:0 5px;color:#000}.wpbdp-license-expired-warning .dismiss{margin-right:10px}.wp-admin.widgets-php .widget-content span.help{color:#666}
|
admin/resources/admin.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
var WPBDP_associations_fieldtypes={};(function($){var WPBDPAdmin_FormFields={$f_association:null,$f_fieldtype:null,init:function(){WPBDPAdmin_FormFields.$f_association=$("form#wpbdp-formfield-form select#field-association");WPBDPAdmin_FormFields.$f_association.change(WPBDPAdmin_FormFields.onAssociationChange);WPBDPAdmin_FormFields.$f_fieldtype=$("form#wpbdp-formfield-form select#field-type");WPBDPAdmin_FormFields.$f_fieldtype.change(WPBDPAdmin_FormFields.onFieldTypeChange);$("table.formfields tbody").sortable({placeholder:"wpbdp-draggable-highlight",handle:".wpbdp-drag-handle",axis:"y",cursor:"move",opacity:0.9,update:function(event,ui){var sorted_items=[];$(this).find(".wpbdp-drag-handle").each(function(i,v){sorted_items.push($(v).attr("data-field-id"))});if(sorted_items){$.post(ajaxurl,{action:"wpbdp-formfields-reorder",order:sorted_items})}}})},onFieldTypeChange:function(){var $field_type=$(this).find("option:selected");if(!$field_type.length){return}var field_type=$field_type.val();var request_data={action:"wpbdp-renderfieldsettings",association:WPBDPAdmin_FormFields.$f_association.find("option:selected").val(),field_type:field_type,field_id:$('#wpbdp-formfield-form input[name="field[id]"]').val()};$.post(ajaxurl,request_data,function(response){if(response.ok&&response.html){$("#wpbdp-fieldsettings-html").html(response.html);$("#wpbdp-fieldsettings").show()}else{$("#wpbdp-fieldsettings-html").empty();$("#wpbdp-fieldsettings").hide()}},"json")},onAssociationChange:function(){$f_fieldtype=WPBDPAdmin_FormFields.$f_fieldtype;var association=$(this).find("option:selected").val();var valid_types=WPBDP_associations_fieldtypes[association];$f_fieldtype.find("option").removeAttr("disabled");$f_fieldtype.find("option").each(function(i,v){if($.inArray($(v).val(),valid_types)<0){$(v).attr("disabled","disabled")}});if($f_fieldtype.find("option:selected").attr("disabled")=="disabled"){$f_fieldtype.find("option").removeAttr("selected");$f_fieldtype.find('option[value="'+valid_types[0]+'"]').attr("selected","selected")}}};$(document).ready(function(){WPBDPAdmin_FormFields.init()})})(jQuery);jQuery(document).ready(function($){$('form#wpbdp-fee-form input[name="_days"]').change(function(){var value=$(this).val();if(value==0){$("form input#wpbdp-fee-form-days-n").attr("disabled",true);$('form input[name="fee[days]"]').val("0")}else{$("form input#wpbdp-fee-form-days-n").removeAttr("disabled");$('form input[name="fee[days]"]').val($("form input#wpbdp-fee-form-days-n").val());$("form input#wpbdp-fee-form-days-n").focus()}return true});$(".wpbdp-page-admin-fees .wp-list-table.fees tbody").sortable({placeholder:"wpbdp-draggable-highlight",handle:".wpbdp-drag-handle",axis:"y",cursor:"move",opacity:0.9,update:function(event,ui){var sorted_items=[];$(this).find(".wpbdp-drag-handle").each(function(i,v){sorted_items.push($(v).attr("data-fee-id"))});if(sorted_items){$.post(ajaxurl,{action:"wpbdp-admin-fees-reorder",order:sorted_items})}}});$("form#wpbdp-fee-form").submit(function(){$('form input[name="fee[days]"]').removeAttr("disabled");return true});$('select[name="fee_order[method]"], select[name="fee_order[order]"]').change(function(e){$.ajax({url:ajaxurl,data:$(this).parent("form").serialize(),dataType:"json",type:"POST",success:function(res){if(res.success){location.reload()}}})});if("custom"==$('select[name="fee_order[method]"]').val()){$(".wpbdp-page-admin-fees .wp-list-table .wpbdp-drag-handle").show()}$("#BusinessDirectory_listinginfo .listing-metabox-tabs a").click(function(e){e.preventDefault();var href=$(this).attr("href");var $selected=$(this).parent("li").siblings(".selected");if($selected.length>0){if($selected.find("a:first").attr("href")==href){return}else{$selected.removeClass("selected");$($selected.find("a:first").attr("href")).hide()}}$(this).parent("li").addClass("selected");$(href).show();$(".listing-fee-expiration-datepicker").hide()});$("#BusinessDirectory_listinginfo .listing-metabox-tabs li.selected a").click();$("#listing-metabox-fees a.assignfee-link").click(function(e){e.preventDefault();$(this).siblings(".assignfee").show()});$("#listing-metabox-fees .assignfee .close-handle").click(function(e){e.preventDefault();$(this).parent(".assignfee").hide()});$(".wpbdp-ajax-placeholder").each(function(i,v){wpbdp_load_placeholder($(v))});$("input#doaction, input#doaction2").click(function(e){var action_name=("doaction"==$(this).attr("id"))?"action":"action2";var $selected_option=$('select[name="'+action_name+'"] option:selected');var action_val=$selected_option.val();if(action_val.split("-")[0]=="listing"){var action=action_val.split("-")[1];if(action!="sep0"&&action!="sep1"&&action!="sep2"){var $checked_posts=$('input[name="post[]"]:checked');var uri=$selected_option.attr("data-uri");$checked_posts.each(function(i,v){uri+="&post[]="+$(v).val()});window.location.href=uri;return false}}return true});$('.wpbdp-admin.wpbdp-page-formfields-preview form input[type="submit"]').click(function(e){e.preventDefault();alert("This form is just a preview. It doesn't work.")});$("form#wpbdp-csv-import-form input.assign-listings-to-user").change(function(e){if($(this).is(":checked")){$("form#wpbdp-csv-import-form .default-user-selection").show()}else{$("form#wpbdp-csv-import-form .default-user-selection").hide()}}).change();$("#wpbdp-admin-debug-info-page a.nav-tab").click(function(e){e.preventDefault();$("#wpbdp-admin-debug-info-page a.nav-tab").not(this).removeClass("nav-tab-active");var $selected_tab=$(this);$selected_tab.addClass("nav-tab-active");$(".wpbdp-debug-section").hide();$('.wpbdp-debug-section[data-id="'+$(this).attr("href")+'"]').show()});if($("#wpbdp-admin-debug-info-page a.nav-tab").length>0){$("#wpbdp-admin-debug-info-page a.nav-tab").get(0).click()}$(".wpbdp-page-admin-transactions .column-actions a.details-link").click(function(e){e.preventDefault();var $tr=$(this).parents("tr");var $details=$tr.find("div.more-details");var $tr_details=$tr.next("tr.more-details-row");if($tr_details.length>0){$tr_details.remove();$(this).text($(this).text().replace("-","+"));return}else{$(this).text($(this).text().replace("+","-"))}$tr.after('<tr class="more-details-row"><td colspan="7">'+$details.html()+"</td></tr>").show()})});function wpbdp_load_placeholder($v){var action=$v.attr("data-action");var post_id=$v.attr("data-post_id");var baseurl=$v.attr("data-baseurl");$v.load(ajaxurl,{action:action,post_id:post_id,baseurl:baseurl})}var WPBDP_Admin={};WPBDP_Admin.payments={};WPBDP_Admin.listingMetabox={};WPBDP_Admin.ProgressBar=function($item,settings){$item.empty();$item.html('<div class="wpbdp-progress-bar"><span class="progress-text">0%</span><div class="progress-bar"><div class="progress-bar-outer"><div class="progress-bar-inner" style="width: 0%;"></div></div></div>');this.$item=$item;this.$text=$item.find(".progress-text");this.$bar=$item.find(".progress-bar");this.set=function(completed,total){var pcg=Math.round(100*parseInt(completed)/parseInt(total));this.$text.text(pcg+"%");this.$bar.find(".progress-bar-inner").attr("style","width: "+pcg+"%;")}};(function($){WPBDP_Admin.dialog={};var dialog=WPBDP_Admin.dialog})(jQuery);(function($){var payments=WPBDP_Admin.payments;payments._initialize=function(){$("#BusinessDirectory_listinginfo a.payment-details-link").click(function(e){e.preventDefault();payments.viewPaymentDetails($(this).attr("data-id"))});if($("#wpbdp-modal-dialog").length==0){$("body").append($('<div id="wpbdp-modal-dialog"></div>'))}};payments.viewPaymentDetails=function(id){$.get(ajaxurl,{action:"wpbdp-payment-details",id:id},function(res){if(res&&res.success){if($("#wpbdp-modal-dialog").length==0){$("body").append($('<div id="wpbdp-modal-dialog"></div>'))}$("#wpbdp-modal-dialog").html(res.data.html);tb_show("","#TB_inline?inlineId=wpbdp-modal-dialog");$("#wpbdp-modal-dialog").remove()}},"json")};$(document).ready(function(){payments._initialize()})})(jQuery);(function($){var metabox=WPBDP_Admin.listingMetabox;metabox._initialize=function(){$("#listing-metabox-generalinfo, #listing-metabox-fees").each(function(i,v){var $tab=$(v);$tab.find(".expiration-date-info .datepicker").each(function(i,v){var $dp=$(v);var $changeLink=$dp.siblings("a.expiration-change-link");$dp.hide().datepicker({dateFormat:"yy-mm-dd",defaultDate:$changeLink.attr("data-date"),onSelect:function(newDate){if(newDate){var $expirationDate=$(this).siblings(".expiration-date");var $spinner=$(this).parents(".listing-category").find(".spinner:first");$expirationDate.text("--");$spinner.show();$.post(ajaxurl,{action:"wpbdp-listing_set_expiration",renewal_id:$changeLink.attr("data-renewal_id"),expiration_date:newDate},function(res){if(res&&res.success){$spinner.hide()}$expirationDate.text(res.data.formattedExpirationDate).show()},"json")}$(this).hide()}})});$tab.find("a.expiration-change-link").click(function(e){e.preventDefault();var renewal_id=$(this).attr("data-renewal_id");$(".expiration-date-info .datepicker").not(".renewal-"+renewal_id).hide();$(".expiration-date-info .datepicker.renewal-"+renewal_id).toggle()})});$(".listing-category a.category-delete").click(function(e){e.preventDefault();var listingID=$(this).attr("data-listing");var categoryID=$(this).attr("data-category");if(!listingID||!categoryID){return}var $category=$(".listing-category-"+categoryID);$.post(ajaxurl,{action:"wpbdp-listing_remove_category",listing:listingID,category:categoryID},function(res){if(res&&res.success){$('input[name="tax_input[wpbdp_category][]"][value="'+categoryID+'"]').attr("checked",false);$category.fadeOut(function(){$(this).remove()})}},"json")});$(".listing-category a.category-change-fee").click(function(e){e.preventDefault();if($("#wpbdp-modal-dialog").length==0){$("body").append($('<div id="wpbdp-modal-dialog"></div>'))}$.post(ajaxurl,{action:"wpbdp-listing_change_fee",renewal:$(this).attr("data-renewal")},function(res){if(res&&res.success){$("#wpbdp-modal-dialog").html(res.data.html);tb_show("","#TB_inline?inlineId=wpbdp-modal-dialog");$("#wpbdp-modal-dialog").remove()}},"json")})};$(document).ready(function(){if($("#listing-metabox-fees").length>0){metabox._initialize()}})})(jQuery);(function($){var s=WPBDP_Admin.settings={_whenTrueActivateChilds:{},init:function(){var t=this;$(".wpbdp-settings-email").each(function(i,v){var $email=$(v);var $preview=$email.find(".short-preview");var $editor=$email.find(".editor");var $subject=$editor.find(".subject-text");var $body=$editor.find(".body-text");var data={subject:"",body:""};$preview.click(function(e){data.subject=$subject.val();data.body=$body.val();$preview.hide();$editor.show()});$(".cancel",$editor).click(function(e){e.preventDefault();$subject.val(data.subject);$body.val(data.body);$editor.hide();$preview.show()});$(".save",$editor).click(function(e){e.preventDefault();$("form#wpbdp-admin-settings #submit").click()});$(".preview-email",$editor).click(function(e){e.preventDefault();var subject=$subject.val();var body=$body.val();$.ajax({url:ajaxurl,data:{action:"wpbdp-admin-settings-email-preview",nonce:$editor.attr("data-preview-nonce"),setting:$email.attr("data-setting"),subject:subject,body:body},dataType:"json",type:"POST",success:function(res){if(!res.success){return}if(0==$("#wpbdp-modal-dialog").length){$("body").append('<div id="wpbdp-modal-dialog" style="display: none;"></div>')}$("#wpbdp-modal-dialog").html(res.data.html);tb_show("","#TB_inline?inlineId=wpbdp-modal-dialog");$("#wpbdp-modal-dialog").remove()}})})});$("select#quick-search-fields").change(function(){var selected=$(this).find("option.textfield:selected").length;if(selected>0){$("span.text-fields-warning").fadeIn("fast")}else{$("span.text-fields-warning").fadeOut("fast")}});$.each(this._whenTrueActivateChilds,function(p,chs){$('input[name="wpbdp-'+p+'"]').change(function(e){t.handleToggle(p)});t.handleToggle(p)})},handleToggle:function(setting){var childs=this._whenTrueActivateChilds[setting];if("undefined"===typeof(childs)){return}var checked=$('input[name="wpbdp-'+setting+'"]').is(":checked");$.each(this._whenTrueActivateChilds[setting],function(i,c){var $c=$('[name="wpbdp-'+c+'"], [name="wpbdp-'+c+'[]"]');var $row=$c.parents("tr");if(checked){$c.removeAttr("contenteditable");$row.removeClass("disabled")}else{$c.attr("contenteditable","false");$row.addClass("disabled")}})},add_requirement:function(setting,parent_,req){if("undefined"===typeof this._whenTrueActivateChilds[parent_]){this._whenTrueActivateChilds[parent_]=[]}this._whenTrueActivateChilds[parent_].push(setting)}};$(document).ready(function(){if(0==$("body.directory-admin_page_wpbdp_admin_settings").length){return}s.init()})})(jQuery);(function($){var u=WPBDP_Admin.uninstall={init:function(){$('form#wpbdp-uninstall-capture-form input[name="uninstall[reason_id]"]').change(function(e){var val=$(this).val();if("0"==val){$('form#wpbdp-uninstall-capture-form textarea[name="uninstall[reason_text]"]').fadeIn()}else{$('form#wpbdp-uninstall-capture-form textarea[name="uninstall[reason_text]"]').fadeOut("fast",function(){$(this).val("")})}})}};$(document).ready(function(){if($("body.directory-admin_page_wpbdp_uninstall").length>0){u.init()}})})(jQuery);(function($){$(document).ready(function(){if($("body.wp-admin.widgets-php").length==0){return}$("input.wpbdp-toggle-images").change(function(){var checked=$(this).is(":checked");if(checked){$(this).parents(".widget").find(".thumbnail-width-config, .thumbnail-height-config").fadeIn("fast")}else{$(this).parents(".widget").find(".thumbnail-width-config, .thumbnail-height-config").fadeOut("fast")}})})})(jQuery);(function($){$(document).ready(function(){$("a.wpbdp-create-main-page-button").click(function(e){e.preventDefault();var $msg=$(this).parents("div.error");$.ajax({url:ajaxurl,data:{action:"wpbdp-create-main-page",_wpnonce:$(this).attr("data-nonce")},dataType:"json",success:function(res){if(!res.success){return}$msg.fadeOut("fast",function(){$(this).html("<p>"+res.message+"</p>");$(this).removeClass("error");$(this).addClass("updated");$(this).fadeIn("fast")})}})})})})(jQuery);(function($){var l=WPBDP_Admin.licensing={init:function(){$("input.license-activate").click(function(){var module=$(this).parent(".license-activation").attr("data-module-id");var license=$('input[type="text"]#license-key-'+module).val();l.activation_change(module,license,"activate")});$("input.license-deactivate").click(function(){var module=$(this).parent(".license-activation").attr("data-module-id");var license=$('input[type="text"]#license-key-'+module);l.activation_change(module,"","deactivate")})},activation_change:function(module,license,action){var $container=$('.license-activation[data-module-id="'+module+'"]');var $msg=$(".status-message",$container);var nonce=$('input[name="nonce"]',$container).val();$msg.removeClass("ok error");$msg.html($("input.license-"+action,$container).attr("data-L10n"));$.post(ajaxurl,{action:"wpbdp-"+action+"-license",module:module,key:license,nonce:nonce},function(res){if(res.success){$msg.hide().html(res.message).removeClass("error").addClass("ok").show();$("input.license-"+action,$container).hide();$('input[type="button"]',$container).not(".license-"+action).show();if("activate"==action){$('input[type="text"]#license-key-'+module).attr("readonly","readonly")}else{$('input[type="text"]#license-key-'+module).removeAttr("readonly")}}else{$msg.hide().html(res.error).removeClass("ok").addClass("error").show();if("deactivate"==action){$('input[type="text"]#license-key-'+module).removeAttr("readonly")}}},"json")}};$(document).ready(function(){if($("input.license-activate, input.license-deactivate").length>0){l.init()}if($(".wpbdp-license-expired-warning").length>0){$(".wpbdp-license-expired-warning .dismiss").click(function(e){e.preventDefault();var module_id=$(this).attr("data-module");var nonce=$(this).attr("data-nonce");var $warning=$(this).parents(".wpbdp-license-expired-warning");$.post(ajaxurl,{action:"wpbdp-license-expired-warning-dismiss",nonce:nonce,module:module_id},function(res){if(res.success){$warning.fadeOut("fast")}},"json")})}})})(jQuery);
|
admin/resources/check.png
ADDED
Binary file
|
admin/resources/drag-handle.png
ADDED
Binary file
|
admin/resources/export.css
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.wpbdp-page-csv-export .step-2 {
|
2 |
+
display: none;
|
3 |
+
}
|
4 |
+
|
5 |
+
.wpbdp-page-csv-export .step-3 {
|
6 |
+
display: none;
|
7 |
+
}
|
8 |
+
|
9 |
+
.wpbdp-page-csv-export .step-3 .download-link {
|
10 |
+
}
|
11 |
+
|
12 |
+
.wpbdp-page-csv-export .step-3 .cleanup-link {
|
13 |
+
display: none;
|
14 |
+
margin-top: 20px;
|
15 |
+
}
|
16 |
+
|
17 |
+
.wpbdp-page-csv-export .canceled-export {
|
18 |
+
display: none;
|
19 |
+
}
|
admin/resources/export.js
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(function($) {
|
2 |
+
var progressBar = new WPBDP_Admin.ProgressBar($('.step-2 .export-progress'));
|
3 |
+
|
4 |
+
var exportInProgress = false;
|
5 |
+
var cancelExport = false;
|
6 |
+
var lastState = null;
|
7 |
+
|
8 |
+
var handleError = function(msg, res) {
|
9 |
+
if (msg)
|
10 |
+
$('.wpbdp-page-csv-export div.error p').text(msg);
|
11 |
+
|
12 |
+
if (res && res.state) {
|
13 |
+
$.ajax(ajaxurl, {data: { 'action': 'wpbdp-csv-export', 'state': state, 'cleanup': 1}, type: 'POST' });
|
14 |
+
}
|
15 |
+
|
16 |
+
cancelExport = true;
|
17 |
+
exportInProgress = false;
|
18 |
+
|
19 |
+
$('.step-1, .step-2, .step-3').hide();
|
20 |
+
$('.wpbdp-page-csv-export div.error').show();
|
21 |
+
$('.canceled-export').show();
|
22 |
+
|
23 |
+
$('html, body').animate({ scrollTop: 0 }, 'medium');
|
24 |
+
};
|
25 |
+
|
26 |
+
var advanceExport = function(state) {
|
27 |
+
if (!exportInProgress)
|
28 |
+
return;
|
29 |
+
|
30 |
+
lastState = state;
|
31 |
+
|
32 |
+
if (cancelExport) {
|
33 |
+
exportInProgress = false
|
34 |
+
cancelExport = false;
|
35 |
+
|
36 |
+
$('.step-2').fadeOut(function() {
|
37 |
+
$('.canceled-export').fadeIn();
|
38 |
+
});
|
39 |
+
|
40 |
+
$.ajax(ajaxurl, {
|
41 |
+
data: { 'action': 'wpbdp-csv-export', 'state': state, 'cleanup': 1 },
|
42 |
+
type: 'POST',
|
43 |
+
dataType: 'json',
|
44 |
+
success: function(res) {
|
45 |
+
}
|
46 |
+
});
|
47 |
+
return;
|
48 |
+
}
|
49 |
+
|
50 |
+
$.ajax(ajaxurl, {
|
51 |
+
data: { 'action': 'wpbdp-csv-export', 'state': state },
|
52 |
+
type: 'POST',
|
53 |
+
dataType: 'json',
|
54 |
+
success: function(res) {
|
55 |
+
if (!res || res.error) {
|
56 |
+
exportInProgress = false;
|
57 |
+
handleError((res && res.error) ? res.error : null, res);
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
|
61 |
+
$('.step-2 .listings').text(res.exported + ' / ' + res.count);
|
62 |
+
$('.step-2 .size').text(res.filesize);
|
63 |
+
progressBar.set(res.exported, res.count);
|
64 |
+
|
65 |
+
if (res.isDone) {
|
66 |
+
exportInProgress = false;
|
67 |
+
|
68 |
+
$('.step-2').fadeOut(function() {
|
69 |
+
$('.step-3 .download-link a').attr('href', res.fileurl);
|
70 |
+
$('.step-3 .download-link a .filename').text(res.filename);
|
71 |
+
$('.step-3 .download-link a .filesize').text(res.filesize);
|
72 |
+
|
73 |
+
$('.step-3').fadeIn(function() {
|
74 |
+
$('.step-3 .cleanup-link').hide();
|
75 |
+
})
|
76 |
+
} );
|
77 |
+
|
78 |
+
} else {
|
79 |
+
advanceExport(res.state);
|
80 |
+
}
|
81 |
+
},
|
82 |
+
error: function() { handleError(); }
|
83 |
+
});
|
84 |
+
};
|
85 |
+
|
86 |
+
|
87 |
+
$('form#wpbdp-csv-export-form').submit(function(e) {
|
88 |
+
e.preventDefault();
|
89 |
+
|
90 |
+
var data = $(this).serialize() + '&action=wpbdp-csv-export';
|
91 |
+
$.ajax(ajaxurl, {
|
92 |
+
data: data,
|
93 |
+
type: 'POST',
|
94 |
+
dataType: 'json',
|
95 |
+
success: function(res) {
|
96 |
+
if (!res || res.error) {
|
97 |
+
exportInProgress = false;
|
98 |
+
handleError((res && res.error) ? res.error : null, res);
|
99 |
+
return;
|
100 |
+
}
|
101 |
+
|
102 |
+
$('.step-1').fadeOut(function(){
|
103 |
+
exportInProgress = true;
|
104 |
+
$('.step-2 .listings').text('0 / ' + res.count);
|
105 |
+
$('.step-2 .size').text('0 KB');
|
106 |
+
|
107 |
+
$('.step-2').fadeIn(function() {
|
108 |
+
advanceExport(res.state);
|
109 |
+
});
|
110 |
+
});
|
111 |
+
},
|
112 |
+
error: function() { handleError(); }
|
113 |
+
});
|
114 |
+
});
|
115 |
+
|
116 |
+
$('a.cancel-import').click(function(e) {
|
117 |
+
e.preventDefault();
|
118 |
+
cancelExport = true;
|
119 |
+
});
|
120 |
+
|
121 |
+
$('.step-3 .download-link a').click(function(e) {
|
122 |
+
$('.step-3 .cleanup-link').fadeIn();
|
123 |
+
});
|
124 |
+
|
125 |
+
$('.step-3 .cleanup-link a').click(function(e) {
|
126 |
+
e.preventDefault();
|
127 |
+
$.ajax(ajaxurl, {
|
128 |
+
data: { 'action': 'wpbdp-csv-export', 'state': lastState, 'cleanup': 1 },
|
129 |
+
type: 'POST',
|
130 |
+
dataType: 'json',
|
131 |
+
success: function(res) {
|
132 |
+
location.href = '';
|
133 |
+
}
|
134 |
+
});
|
135 |
+
});
|
136 |
+
});
|
admin/resources/export.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.wpbdp-page-csv-export .step-2{display:none}.wpbdp-page-csv-export .step-3{display:none}.wpbdp-page-csv-export .step-3 .cleanup-link{display:none;margin-top:20px}.wpbdp-page-csv-export .canceled-export{display:none}
|
admin/resources/export.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jQuery(function($){var progressBar=new WPBDP_Admin.ProgressBar($(".step-2 .export-progress"));var exportInProgress=false;var cancelExport=false;var lastState=null;var handleError=function(msg,res){if(msg){$(".wpbdp-page-csv-export div.error p").text(msg)}if(res&&res.state){$.ajax(ajaxurl,{data:{action:"wpbdp-csv-export",state:state,cleanup:1},type:"POST"})}cancelExport=true;exportInProgress=false;$(".step-1, .step-2, .step-3").hide();$(".wpbdp-page-csv-export div.error").show();$(".canceled-export").show();$("html, body").animate({scrollTop:0},"medium")};var advanceExport=function(state){if(!exportInProgress){return}lastState=state;if(cancelExport){exportInProgress=false;cancelExport=false;$(".step-2").fadeOut(function(){$(".canceled-export").fadeIn()});$.ajax(ajaxurl,{data:{action:"wpbdp-csv-export",state:state,cleanup:1},type:"POST",dataType:"json",success:function(res){}});return}$.ajax(ajaxurl,{data:{action:"wpbdp-csv-export",state:state},type:"POST",dataType:"json",success:function(res){if(!res||res.error){exportInProgress=false;handleError((res&&res.error)?res.error:null,res);return}$(".step-2 .listings").text(res.exported+" / "+res.count);$(".step-2 .size").text(res.filesize);progressBar.set(res.exported,res.count);if(res.isDone){exportInProgress=false;$(".step-2").fadeOut(function(){$(".step-3 .download-link a").attr("href",res.fileurl);$(".step-3 .download-link a .filename").text(res.filename);$(".step-3 .download-link a .filesize").text(res.filesize);$(".step-3").fadeIn(function(){$(".step-3 .cleanup-link").hide()})})}else{advanceExport(res.state)}},error:function(){handleError()}})};$("form#wpbdp-csv-export-form").submit(function(e){e.preventDefault();var data=$(this).serialize()+"&action=wpbdp-csv-export";$.ajax(ajaxurl,{data:data,type:"POST",dataType:"json",success:function(res){if(!res||res.error){exportInProgress=false;handleError((res&&res.error)?res.error:null,res);return}$(".step-1").fadeOut(function(){exportInProgress=true;$(".step-2 .listings").text("0 / "+res.count);$(".step-2 .size").text("0 KB");$(".step-2").fadeIn(function(){advanceExport(res.state)})})},error:function(){handleError()}})});$("a.cancel-import").click(function(e){e.preventDefault();cancelExport=true});$(".step-3 .download-link a").click(function(e){$(".step-3 .cleanup-link").fadeIn()});$(".step-3 .cleanup-link a").click(function(e){e.preventDefault();$.ajax(ajaxurl,{data:{action:"wpbdp-csv-export",state:lastState,cleanup:1},type:"POST",dataType:"json",success:function(res){location.href=""}})})});
|
admin/resources/manual-upgrade.js
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(function($) {
|
2 |
+
var $startButton = $('.wpbdp-page-manual-upgrade a.start-upgrade');
|
3 |
+
var $pauseButton = $('.wpbdp-page-manual-upgrade a.pause-upgrade');
|
4 |
+
var $progressArea = $('textarea#manual-upgrade-progress');
|
5 |
+
var inProgress = false;
|
6 |
+
|
7 |
+
var makeProgress = function() {
|
8 |
+
if (!inProgress)
|
9 |
+
return;
|
10 |
+
|
11 |
+
var data = { action: 'wpbdp-manual-upgrade' };
|
12 |
+
$.get(ajaxurl, data, function(response) {
|
13 |
+
var currentText = $progressArea.val();
|
14 |
+
var newLine = (response.ok ? "*" : "!") + " " + response.status;
|
15 |
+
|
16 |
+
$progressArea.val(currentText + newLine + "\n");
|
17 |
+
$progressArea.scrollTop($progressArea[0].scrollHeight - $progressArea.height());
|
18 |
+
|
19 |
+
if (response.done) {
|
20 |
+
$( 'div.step-upgrade' ).fadeOut(function() { $('div.step-done').fadeIn() });
|
21 |
+
} else {
|
22 |
+
makeProgress();
|
23 |
+
}
|
24 |
+
}, 'json');
|
25 |
+
};
|
26 |
+
|
27 |
+
$startButton.click(function(e) {
|
28 |
+
e.preventDefault();
|
29 |
+
|
30 |
+
if (inProgress)
|
31 |
+
return;
|
32 |
+
|
33 |
+
inProgress = true;
|
34 |
+
makeProgress();
|
35 |
+
});
|
36 |
+
|
37 |
+
$pauseButton.click(function(e) {
|
38 |
+
e.preventDefault();
|
39 |
+
inProgress = false;
|
40 |
+
});
|
41 |
+
|
42 |
+
});
|
admin/resources/manual-upgrade.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jQuery(function($){var $startButton=$(".wpbdp-page-manual-upgrade a.start-upgrade");var $pauseButton=$(".wpbdp-page-manual-upgrade a.pause-upgrade");var $progressArea=$("textarea#manual-upgrade-progress");var inProgress=false;var makeProgress=function(){if(!inProgress){return}var data={action:"wpbdp-manual-upgrade"};$.get(ajaxurl,data,function(response){var currentText=$progressArea.val();var newLine=(response.ok?"*":"!")+" "+response.status;$progressArea.val(currentText+newLine+"\n");$progressArea.scrollTop($progressArea[0].scrollHeight-$progressArea.height());if(response.done){$("div.step-upgrade").fadeOut(function(){$("div.step-done").fadeIn()})}else{makeProgress()}},"json")};$startButton.click(function(e){e.preventDefault();if(inProgress){return}inProgress=true;makeProgress()});$pauseButton.click(function(e){e.preventDefault();inProgress=false})});
|
admin/resources/menuico.png
ADDED
Binary file
|
admin/resources/new.gif
ADDED
Binary file
|
admin/resources/payfast-payment-module.png
ADDED
Binary file
|
admin/resources/paypal-gateway-module.png
ADDED
Binary file
|
admin/resources/stripe-payment-module.png
ADDED
Binary file
|
admin/templates/csv-export.tpl.php
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header( null, 'csv-export' );
|
3 |
+
?>
|
4 |
+
|
5 |
+
<?php echo wpbdp_admin_notices(); ?>
|
6 |
+
|
7 |
+
<a name="exporterror"></a>
|
8 |
+
<div class="error" style="display: none;"><p>
|
9 |
+
<?php _ex( 'An unknown error occurred during the export. Please make sure you have enough free disk space and memory available to PHP. Check your error logs for details.',
|
10 |
+
'admin csv-export',
|
11 |
+
'WPBDM' ); ?>
|
12 |
+
</p></div>
|
13 |
+
|
14 |
+
<div class="step-1">
|
15 |
+
|
16 |
+
<div class="wpbdp-note"><p>
|
17 |
+
<?php
|
18 |
+
$notice = _x( "Please note that the export process is a resource intensive task. If your export does not succeed try disabling other plugins first and/or increasing the values of the 'memory_limit' and 'max_execution_time' directives in your server's php.ini configuration file.",
|
19 |
+
'admin csv-export',
|
20 |
+
'WPBDM' );
|
21 |
+
$notice = str_replace( array( 'memory_limit', 'max_execution_time' ),
|
22 |
+
array( '<a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit" target="_blank">memory_limit</a>',
|
23 |
+
'<a href="http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time" target="_blank">max_execution_time</a>' ),
|
24 |
+
$notice );
|
25 |
+
echo $notice;
|
26 |
+
?>
|
27 |
+
</p>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<!--<h3><?php _ex('Export Configuration', 'admin csv-export', 'WPBDM'); ?></h3>-->
|
31 |
+
<form id="wpbdp-csv-export-form" action="" method="POST">
|
32 |
+
|
33 |
+
<h3><?php _ex( 'Export settings', 'admin csv-export', 'WPBDM' ); ?></h3>
|
34 |
+
<table class="form-table">
|
35 |
+
<tr>
|
36 |
+
<th scope="row">
|
37 |
+
<label> <?php _ex('Which listings to export?', 'admin csv-export', 'WPBDM'); ?></label>
|
38 |
+
</th>
|
39 |
+
<td>
|
40 |
+
<select name="settings[listing_status]">
|
41 |
+
<option value="all"><?php _ex( 'All', 'admin csv-export', 'WPBDM' ); ?></option>
|
42 |
+
<option value="publish"><?php _ex( 'Active Only', 'admin csv-export', 'WPBDM' ); ?></option>
|
43 |
+
<option value="publish+draft"><?php _ex( 'Active + Pending Renewal', 'admin csv-export', 'WPBDM' ); ?></option>
|
44 |
+
</select>
|
45 |
+
</td>
|
46 |
+
</tr>
|
47 |
+
<tr>
|
48 |
+
<th scope="row">
|
49 |
+
<label> <?php _ex('Export images?', 'admin csv-export', 'WPBDM'); ?></label>
|
50 |
+
</th>
|
51 |
+
<td>
|
52 |
+
<label><input name="settings[export-images]"
|
53 |
+
type="checkbox"
|
54 |
+
value="1" /> <?php _ex('Export images', 'admin csv-export', 'WPBDM'); ?></label> <br />
|
55 |
+
<span class="description">
|
56 |
+
<?php _ex( 'When checked, instead of just a CSV file a ZIP file will be generated with both a CSV file and listing images.', 'admin csv-export', 'WPBDM' ); ?>
|
57 |
+
</span>
|
58 |
+
</td>
|
59 |
+
</tr>
|
60 |
+
<tr>
|
61 |
+
<th scope="row">
|
62 |
+
<label> <?php _ex('Additional metadata to export:', 'admin csv-export', 'WPBDM'); ?></label>
|
63 |
+
</th>
|
64 |
+
<td>
|
65 |
+
<label><input name="settings[generate-sequence-ids]"
|
66 |
+
type="checkbox"
|
67 |
+
value="1" /> <?php _ex('Include unique IDs for each listing (sequence_id column)', 'admin csv-export', 'WPBDM'); ?></label> <br />
|
68 |
+
|
69 |
+
<label><input name="settings[include-users]"
|
70 |
+
type="checkbox"
|
71 |
+
value="1"
|
72 |
+
checked="checked" /> <?php _ex('Author information (username)', 'admin csv-export', 'WPBDM'); ?></label> <br />
|
73 |
+
|
74 |
+
<label><input name="settings[include-sticky-status]"
|
75 |
+
type="checkbox"
|
76 |
+
value="1"
|
77 |
+
checked="checked" /> <?php _ex('Sticky/featured status', 'admin csv-export', 'WPBDM'); ?></label> <br />
|
78 |
+
|
79 |
+
<label><input name="settings[include-expiration-date]"
|
80 |
+
type="checkbox"
|
81 |
+
value="1"
|
82 |
+
checked="checked" /> <?php _ex('Listing expiration date', 'admin csv-export', 'WPBDM'); ?></label> <br />
|
83 |
+
</td>
|
84 |
+
</tr>
|
85 |
+
</table>
|
86 |
+
|
87 |
+
<h3><?php _ex('CSV File Settings', 'admin csv-export', 'WPBDM'); ?></h3>
|
88 |
+
<table class="form-table">
|
89 |
+
<tr class="form-required">
|
90 |
+
<th scope="row">
|
91 |
+
<label> <?php _ex('Column Separator', 'admin csv-export', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
92 |
+
</th>
|
93 |
+
<td>
|
94 |
+
<input name="settings[csv-file-separator]"
|
95 |
+
type="text"
|
96 |
+
aria-required="true"
|
97 |
+
value="," />
|
98 |
+
</td>
|
99 |
+
</tr>
|
100 |
+
<tr class="form-required">
|
101 |
+
<th scope="row">
|
102 |
+
<label> <?php _ex('Image Separator', 'admin csv-export', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
103 |
+
</th>
|
104 |
+
<td>
|
105 |
+
<input name="settings[images-separator]"
|
106 |
+
type="text"
|
107 |
+
aria-required="true"
|
108 |
+
value=";" />
|
109 |
+
</td>
|
110 |
+
</tr>
|
111 |
+
<tr class="form-required">
|
112 |
+
<th scope="row">
|
113 |
+
<label> <?php _ex('Category Separator', 'admin csv-export', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
114 |
+
</th>
|
115 |
+
<td>
|
116 |
+
<input name="settings[category-separator]"
|
117 |
+
type="text"
|
118 |
+
aria-required="true"
|
119 |
+
value=";" />
|
120 |
+
</td>
|
121 |
+
</tr>
|
122 |
+
</table>
|
123 |
+
|
124 |
+
<p class="submit">
|
125 |
+
<?php echo submit_button( _x( 'Export Listings', 'admin csv-export', 'WPBDM' ), 'primary', 'do-export', false ); ?>
|
126 |
+
</p>
|
127 |
+
</form>
|
128 |
+
</div>
|
129 |
+
|
130 |
+
<div class="step-2">
|
131 |
+
<h3><?php _ex( 'Export in Progress...', 'admin csv-export', 'WPBDM' ); ?></h3>
|
132 |
+
<p><?php _ex( 'Your export file is being prepared. Please <u>do not leave</u> this page until the export finishes.', 'admin csv-export', 'WPBDM' ); ?></p>
|
133 |
+
|
134 |
+
<dl>
|
135 |
+
<dt><?php _ex( 'No. of listings:', 'admin csv-export', 'WPBDM' ); ?></dt>
|
136 |
+
<dd class="listings">?</dd>
|
137 |
+
<dt><?php _ex( 'Approximate export file size:', 'admin csv-export', 'WPBDM' ); ?></dt>
|
138 |
+
<dd class="size">?</dd>
|
139 |
+
</dl>
|
140 |
+
|
141 |
+
<div class="export-progress"></div>
|
142 |
+
|
143 |
+
<p class="submit">
|
144 |
+
<a href="#" class="cancel-import button"><?php _ex( 'Cancel Export', 'admin csv-export', 'WPBDM' ); ?></a>
|
145 |
+
</p>
|
146 |
+
</div>
|
147 |
+
|
148 |
+
<div class="step-3">
|
149 |
+
<h3><?php _ex( 'Export Complete', 'admin csv-export' )?></h3>
|
150 |
+
<p><?php _ex( 'Your export file has been successfully created and it is now ready for download.', 'admin csv-export', 'WPBDM' ); ?></p>
|
151 |
+
<div class="download-link">
|
152 |
+
<a href="" class="button button-primary">
|
153 |
+
<?php echo sprintf( _x( 'Download %s (%s)', 'admin csv-export', 'WPBDM' ),
|
154 |
+
'<span class="filename"></span>',
|
155 |
+
'<span class="filesize"></span>' ); ?>
|
156 |
+
</a>
|
157 |
+
</div>
|
158 |
+
<div class="cleanup-link wpbdp-note">
|
159 |
+
<p><?php _ex( 'Click "Cleanup" once the file has been downloaded in order to remove all temporary data created by Business Directory during the export process.', 'admin csv-export', 'WPBDM' ); ?><br />
|
160 |
+
<a href="" class="button"><?php _ex( 'Cleanup', 'admin csv-export', 'WPBDM' ); ?></a></p>
|
161 |
+
</div>
|
162 |
+
</div>
|
163 |
+
|
164 |
+
<div class="canceled-export">
|
165 |
+
<h3><?php _ex( 'Export Canceled', 'admin csv-export' )?></h3>
|
166 |
+
<p><?php _ex( 'The export has been canceled.', 'admin csv-export', 'WPBDM' ); ?></p>
|
167 |
+
<p><a href="" class="button"><?php _ex( '← Return to CSV Export', 'admin csv-export', 'WPBDM' ); ?></a></p>
|
168 |
+
</div>
|
169 |
+
|
170 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/csv-import.tpl.php
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(null, null, array(
|
3 |
+
array(_x('Help', 'admin csv-import', 'WPBDM'), '#help'),
|
4 |
+
array(_x('See an example CSV import file', 'admin csv-import', 'WPBDM'), esc_url(add_query_arg('action', 'example-csv')))
|
5 |
+
) );
|
6 |
+
?>
|
7 |
+
|
8 |
+
<?php wpbdp_admin_notices(); ?>
|
9 |
+
|
10 |
+
<form id="wpbdp-csv-import-form" action="" method="POST" enctype="multipart/form-data">
|
11 |
+
<input type="hidden" name="action" value="do-import" />
|
12 |
+
|
13 |
+
<h3><?php _ex('Import Files', 'admin csv-import'); ?></h3>
|
14 |
+
<table class="form-table">
|
15 |
+
<tbody>
|
16 |
+
<tr class="form-field form-required">
|
17 |
+
<th scope="row">
|
18 |
+
<label> <?php _ex('CSV File', 'admin csv-import', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
19 |
+
</th>
|
20 |
+
<td>
|
21 |
+
<input name="csv-file"
|
22 |
+
type="file"
|
23 |
+
aria-required="true" />
|
24 |
+
</td>
|
25 |
+
</tr>
|
26 |
+
<tr class="form-field">
|
27 |
+
<th scope="row">
|
28 |
+
<label> <?php _ex('ZIP file containing images', 'admin csv-import', 'WPBDM'); ?></label>
|
29 |
+
</th>
|
30 |
+
<td>
|
31 |
+
<input name="images-file"
|
32 |
+
type="file"
|
33 |
+
aria-required="true" />
|
34 |
+
</td>
|
35 |
+
</tr>
|
36 |
+
</table>
|
37 |
+
|
38 |
+
<h3><?php _ex('CSV File Settings', 'admin csv-import', 'WPBDM'); ?></h3>
|
39 |
+
<table class="form-table">
|
40 |
+
<tr class="form-required">
|
41 |
+
<th scope="row">
|
42 |
+
<label> <?php _ex('Column Separator', 'admin csv-import', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
43 |
+
</th>
|
44 |
+
<td>
|
45 |
+
<input name="settings[csv-file-separator]"
|
46 |
+
type="text"
|
47 |
+
aria-required="true"
|
48 |
+
value="," />
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
<tr class="form-required">
|
52 |
+
<th scope="row">
|
53 |
+
<label> <?php _ex('Image Separator', 'admin csv-import', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
54 |
+
</th>
|
55 |
+
<td>
|
56 |
+
<input name="settings[images-separator]"
|
57 |
+
type="text"
|
58 |
+
aria-required="true"
|
59 |
+
value=";" />
|
60 |
+
</td>
|
61 |
+
</tr>
|
62 |
+
<tr class="form-required">
|
63 |
+
<th scope="row">
|
64 |
+
<label> <?php _ex('Category Separator', 'admin csv-import', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
65 |
+
</th>
|
66 |
+
<td>
|
67 |
+
<input name="settings[category-separator]"
|
68 |
+
type="text"
|
69 |
+
aria-required="true"
|
70 |
+
value=";" />
|
71 |
+
</td>
|
72 |
+
</tr>
|
73 |
+
</table>
|
74 |
+
|
75 |
+
<h3><?php _ex('Import settings', 'admin csv-import', 'WPBDM'); ?></h3>
|
76 |
+
<table class="form-table">
|
77 |
+
<!-- <tr class="form-required">
|
78 |
+
<th scope="row">
|
79 |
+
<label> <?php _ex('Allow partial imports?', 'admin csv-import', 'WPBDM'); ?></label>
|
80 |
+
</th>
|
81 |
+
<td>
|
82 |
+
<label><input name="settings[allow-partial-imports]"
|
83 |
+
type="checkbox"
|
84 |
+
value="1" checked="checked" /> <?php _ex('Allow partial imports.', 'admin csv-import', 'WPBDM'); ?></label>
|
85 |
+
|
86 |
+
<span class="description"><?php _ex('If checked, invalid lines from the CSV file will be ignored.', 'admin csv-import', 'WPBDM'); ?></span>
|
87 |
+
</td>
|
88 |
+
</tr> -->
|
89 |
+
<tr class="form-required">
|
90 |
+
<th scope="row">
|
91 |
+
<label> <?php _ex('Missing categories handling', 'admin csv-import', 'WPBDM'); ?> <span class="description">(<?php _ex('required', 'admin forms'); ?>)</span></label>
|
92 |
+
</th>
|
93 |
+
<td>
|
94 |
+
<label><input name="settings[create-missing-categories]"
|
95 |
+
type="radio"
|
96 |
+
value="1" checked="checked" /> <?php _ex('Auto-create categories', 'admin csv-import', 'WPBDM'); ?></label>
|
97 |
+
<label><input name="settings[create-missing-categories]"
|
98 |
+
type="radio"
|
99 |
+
value="0" /> <?php _ex('Generate errors when a category is not found', 'admin csv-import', 'WPBDM'); ?></label>
|
100 |
+
</td>
|
101 |
+
</tr>
|
102 |
+
<tr class="form-required">
|
103 |
+
<th scope="row">
|
104 |
+
<label> <?php _ex('Assign listings to a user?', 'admin csv-import', 'WPBDM'); ?>
|
105 |
+
</th>
|
106 |
+
<td>
|
107 |
+
<label><input name="settings[assign-listings-to-user]"
|
108 |
+
type="checkbox"
|
109 |
+
class="assign-listings-to-user"
|
110 |
+
value="1" checked="checked" /> <?php _ex('Assign listings to a user.', 'admin csv-import', 'WPBDM'); ?></label>
|
111 |
+
</td>
|
112 |
+
</tr>
|
113 |
+
<tr class="form-required default-user-selection">
|
114 |
+
<th scope="row">
|
115 |
+
<label> <?php _ex('Default listing user', 'admin csv-import', 'WPBDM'); ?>
|
116 |
+
</th>
|
117 |
+
<td>
|
118 |
+
<label>
|
119 |
+
<select name="settings[default-user]" class="default-user">
|
120 |
+
<option value="0"><?php _ex('Use spreadsheet information only.', 'admin csv-import', 'WPBDM'); ?></option>
|
121 |
+
<?php foreach (get_users('orderby=display_name') as $user): ?>
|
122 |
+
<option value="<?php echo $user->ID; ?>"><?php echo $user->display_name; ?> (<?php echo $user->user_login; ?>)</option>
|
123 |
+
<?php endforeach; ?>
|
124 |
+
</select>
|
125 |
+
</label>
|
126 |
+
<span class="description"><?php _ex('This user will be used if the username column is not present in the CSV file.', 'admin csv-import', 'WPBDM'); ?></span>
|
127 |
+
</td>
|
128 |
+
</tr>
|
129 |
+
</table>
|
130 |
+
|
131 |
+
<p class="submit">
|
132 |
+
<?php echo submit_button(_x('Test Import', 'admin csv-import', 'WPBDM'), 'secondary', 'test-import', false); ?>
|
133 |
+
<?php echo submit_button(_x('Import Listings', 'admin csv-import', 'WPBDM'), 'primary', 'do-import', false); ?>
|
134 |
+
</p>
|
135 |
+
</form>
|
136 |
+
|
137 |
+
<hr />
|
138 |
+
<a name="help"></a>
|
139 |
+
<h3><?php _ex('Help', 'admin csv-import', 'WPBDM'); ?></h3>
|
140 |
+
<p>
|
141 |
+
<?php echo sprintf(_x('The following are the valid header names to be used in the CSV file. Multivalued fields (such as category or tags) can appear multiple times in the file. Click <a href="%s">"See an example CSV import file"</a> to see how an import file should look like.', 'admin csv-import', 'WPBDM'),
|
142 |
+
esc_url(add_query_arg('action', 'example-csv'))); ?>
|
143 |
+
</p>
|
144 |
+
|
145 |
+
<table class="wpbdp-csv-import-headers">
|
146 |
+
<thead>
|
147 |
+
<tr>
|
148 |
+
<th class="header-name"><?php _ex('Header name/label', 'admin csv-import', 'WPBDM'); ?></th>
|
149 |
+
<th class="field-label"><?php _ex('Field', 'admin csv-import', 'WPBDM'); ?></th>
|
150 |
+
<th class="field-type"><?php _ex('Type', 'admin csv-import', 'WPBDM'); ?></th>
|
151 |
+
<th class="field-is-required"><?php _ex('Required?', 'admin csv-import', 'WPBDM'); ?></th>
|
152 |
+
<th class="field-is-multivalued"><?php _ex('Multivalued?', 'admin csv-import', 'WPBDM'); ?></th>
|
153 |
+
</tr>
|
154 |
+
</thead>
|
155 |
+
<tbody>
|
156 |
+
<?php $i = 0; foreach ( wpbdp_get_form_fields() as $field ) : ?>
|
157 |
+
<?php
|
158 |
+
if ( 'custom' == $field->get_association() ):
|
159 |
+
continue;
|
160 |
+
endif
|
161 |
+
?>
|
162 |
+
<tr class="<?php echo $i % 2 == 0 ? 'alt' : ''; ?>">
|
163 |
+
<td class="header-name"><?php echo $field->get_short_name(); ?></td>
|
164 |
+
<td class="field-label"><?php echo $field->get_label(); ?></td>
|
165 |
+
<td class="field-type"><?php echo $field->get_field_type()->get_name(); ?></td>
|
166 |
+
<td class="field-is-required"><?php echo $field->is_required() ? 'X' : ''; ?></td>
|
167 |
+
<td class="field-is-multivalued">
|
168 |
+
<?php echo ($field->get_association() == 'category' || $field->get_association() == 'tags') || ($field->get_field_type_id() == 'checkbox' || $field->get_field_type_id() == 'multiselect') ? 'X' : ''; ?>
|
169 |
+
</td>
|
170 |
+
</tr>
|
171 |
+
<?php $i++; endforeach; ?>
|
172 |
+
<tr class="<?php echo $i % 2 == 0 ? 'alt' : ''; ?>">
|
173 |
+
<td class="header-name">images</td>
|
174 |
+
<td class="field-label"><?php _ex('Semicolon separated list of listing images (from the ZIP file)', 'admin csv-import', 'WPBDM'); ?></td>
|
175 |
+
<td class="field-type">-</td>
|
176 |
+
<td class="field-is-required"></td>
|
177 |
+
<td class="field-is-multivalued">X</td>
|
178 |
+
</tr>
|
179 |
+
<tr class="<?php echo ($i + 1) % 2 == 0 ? 'alt' : ''; ?>">
|
180 |
+
<td class="header-name">username</td>
|
181 |
+
<td class="field-label"><?php _ex('Listing author\'s username', 'admin csv-import', 'WPBDM'); ?></td>
|
182 |
+
<td class="field-type">-</td>
|
183 |
+
<td class="field-is-required"></td>
|
184 |
+
<td class="field-is-multivalued"></td>
|
185 |
+
</tr>
|
186 |
+
<tr class="<?php echo ($i + 2) % 2 == 0 ? 'alt' : ''; ?>">
|
187 |
+
<td class="header-name">sequence_id</td>
|
188 |
+
<td class="field-label"><?php _ex( 'Internal Sequence ID used to allow listing updates from external sources.', 'admin csv-import', 'WPBDM' ); ?></td>
|
189 |
+
<td class="field-type">-</td>
|
190 |
+
<td class="field-is-required"></td>
|
191 |
+
<td class="field-is-multivalued"></td>
|
192 |
+
</tr>
|
193 |
+
<tr class="<?php echo ($i + 3) % 2 == 0 ? 'alt' : ''; ?>">
|
194 |
+
<td class="header-name">expires_on</td>
|
195 |
+
<td class="field-label"><?php _ex( 'Date of listing expiration formatted as YYYY-MM-DD. Use this column when adding or updating listings from external sources.', 'admin csv-import', 'WPBDM' ); ?></td>
|
196 |
+
<td class="field-type">-</td>
|
197 |
+
<td class="field-is-required"></td>
|
198 |
+
<td class="field-is-multivalued"></td>
|
199 |
+
</tr>
|
200 |
+
</tbody>
|
201 |
+
</table>
|
202 |
+
|
203 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/debug-info.tpl.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php echo wpbdp_admin_header(); ?>
|
2 |
+
|
3 |
+
<div id="wpbdp-admin-debug-info-page">
|
4 |
+
<p>
|
5 |
+
<?php _ex( 'The following information can help BD developers debug possible problems with your setup.', 'debug-info', 'WPBDM' ); ?>
|
6 |
+
<strong><u><?php _ex( 'The debug information does not contain personal or sensitive information such as passwords or private keys.', 'debug-info', 'WPBDM' ); ?></u></strong>
|
7 |
+
</p>
|
8 |
+
<p style="text-align: right;">
|
9 |
+
<a href="<?php echo add_query_arg( 'download', '1' ); ?>" class="button button-primary"><?php _ex( 'Download Debug Information', 'debug-info', 'WPBDM' ); ?></a>
|
10 |
+
</p>
|
11 |
+
|
12 |
+
<h3 class="nav-tab-wrapper">
|
13 |
+
<?php foreach ( $debug_info as $section_id => &$section ): ?>
|
14 |
+
<a class="nav-tab" href="<?php echo $section_id; ?>"><?php echo $section['_title']; ?></a>
|
15 |
+
<?php endforeach; ?>
|
16 |
+
</h3>
|
17 |
+
|
18 |
+
<?php foreach ( $debug_info as $section_id => &$section ): ?>
|
19 |
+
<table class="wpbdp-debug-section" data-id="<?php echo $section_id; ?>" style="display: none;">
|
20 |
+
<tbody>
|
21 |
+
<?php foreach ( $section as $k => $v ): ?>
|
22 |
+
<?php if ( wpbdp_starts_with( $k, '_') ): continue; endif; ?>
|
23 |
+
<tr>
|
24 |
+
<th scope="row"><?php echo esc_attr( $k ); ?></th>
|
25 |
+
<td><?php echo esc_attr( $v ); ?></td>
|
26 |
+
</tr>
|
27 |
+
<?php endforeach; ?>
|
28 |
+
</tbody>
|
29 |
+
</table>
|
30 |
+
<?php endforeach; ?>
|
31 |
+
</div>
|
32 |
+
|
33 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/fees-addoredit.tpl.php
ADDED
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if (!function_exists('_wpbdp_render_category')) {
|
3 |
+
function _wpbdp_render_category($cat, $selected=array(), $level=0) {
|
4 |
+
$html = '';
|
5 |
+
|
6 |
+
$level_string = str_repeat('— ', $level);
|
7 |
+
$html .= sprintf('<option value="%s" %s>%s%s</option>', $cat->term_id,
|
8 |
+
in_array($cat->term_id, $selected) ? 'selected="selected"' : '',
|
9 |
+
$level_string, $cat->name);
|
10 |
+
|
11 |
+
if ($cat->subcategories) {
|
12 |
+
foreach ($cat->subcategories as $subcat) {
|
13 |
+
$html .= _wpbdp_render_category($subcat, $selected, $level+1);
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
return $html;
|
18 |
+
}
|
19 |
+
}
|
20 |
+
?>
|
21 |
+
|
22 |
+
<?php
|
23 |
+
echo wpbdp_admin_header(_x('Add Listing Fee', 'fees admin', 'WPBDM'));
|
24 |
+
?>
|
25 |
+
<?php wpbdp_admin_notices(); ?>
|
26 |
+
|
27 |
+
<?php
|
28 |
+
$api = wpbdp_fees_api();
|
29 |
+
|
30 |
+
$post_values = isset($_POST['fee']) ? $_POST['fee'] : array();
|
31 |
+
$fee = isset($fee) ? $fee : null;
|
32 |
+
?>
|
33 |
+
|
34 |
+
<form id="wpbdp-fee-form" action="" method="POST">
|
35 |
+
<?php if (isset($fee)): ?>
|
36 |
+
<input type="hidden" name="fee[id]" value="<?php echo $fee->id; ?>" />
|
37 |
+
<?php endif; ?>
|
38 |
+
<table class="form-table">
|
39 |
+
<tbody>
|
40 |
+
<tr class="form-field form-required">
|
41 |
+
<th scope="row">
|
42 |
+
<label> <?php _ex('Fee Label', 'fees admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
43 |
+
</th>
|
44 |
+
<td>
|
45 |
+
<input name="fee[label]"
|
46 |
+
type="text"
|
47 |
+
aria-required="true"
|
48 |
+
value="<?php echo wpbdp_getv($post_values, 'label', $fee ? $fee->label : ''); ?>" />
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
<tr class="form-field form-required">
|
52 |
+
<th scope="row">
|
53 |
+
<label> <?php _ex('Fee Amount', 'fees admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
54 |
+
</th>
|
55 |
+
<td>
|
56 |
+
<input name="fee[amount]"
|
57 |
+
type="text"
|
58 |
+
aria-required="true"
|
59 |
+
value="<?php echo wpbdp_getv($post_values, 'amount', $fee ? $fee->amount : ''); ?>"
|
60 |
+
style="width: 100px;" />
|
61 |
+
</td>
|
62 |
+
</tr>
|
63 |
+
<tr class="form-required">
|
64 |
+
<th scope="row">
|
65 |
+
<label> <?php _ex('Listing run in days', 'fees admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
66 |
+
</th>
|
67 |
+
<td>
|
68 |
+
<?php
|
69 |
+
$days = wpbdp_getv($post_values, 'days', $fee ? $fee->days : '');
|
70 |
+
?>
|
71 |
+
|
72 |
+
<input type="radio" id="wpbdp-fee-form-days" name="_days" value="1" <?php echo $days > 0 ? 'checked="checked"' : ''; ?>/> <label for="wpbdp-fee-form-days"><?php _ex('run listing for', 'fees admin', 'WPBDM'); ?></label>
|
73 |
+
<input id="wpbdp-fee-form-days-n"
|
74 |
+
type="text"
|
75 |
+
aria-required="true"
|
76 |
+
value="<?php echo wpbdp_getv($post_values, 'days', $fee ? $fee->days : '0'); ?>"
|
77 |
+
style="width: 80px;"
|
78 |
+
name="fee[days]"
|
79 |
+
<?php echo wpbdp_getv($post_values, 'days', $fee ? $fee->days : 0) == 0 ? 'disabled="disabled"' : ''; ?>
|
80 |
+
/>
|
81 |
+
<?php _ex('days', 'fees admin', 'WPBDM'); ?>
|
82 |
+
<span class="description">-- or --</span>
|
83 |
+
|
84 |
+
<input type="radio" id="wpbdp-fee-form-days-0" name="_days" value="0" <?php echo $days == 0 ? 'checked="checked"' : ''; ?>/> <label for="wpbdp-fee-form-days-0"><?php _ex('run listing forever', 'fees admin', 'WPBDM'); ?></label>
|
85 |
+
</td>
|
86 |
+
</tr>
|
87 |
+
<tr class="form-field form-required">
|
88 |
+
<th scope="row">
|
89 |
+
<label> <?php _ex('Number of images allowed', 'fees admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
90 |
+
</th>
|
91 |
+
<td>
|
92 |
+
<input name="fee[images]"
|
93 |
+
type="text"
|
94 |
+
aria-required="true"
|
95 |
+
value="<?php echo wpbdp_getv($post_values, 'images', $fee ? $fee->images : '0'); ?>"
|
96 |
+
style="width: 80px;" />
|
97 |
+
</td>
|
98 |
+
</tr>
|
99 |
+
<?php
|
100 |
+
$post_values_categories = wpbdp_getv(isset($post_values['categories']) ? $post_values['categories'] : array(), 'categories', $fee ? $fee->categories['categories'] : array());
|
101 |
+
if ($fee && $fee->categories['all'] && !isset($post_values['categories']['categories'])) $post_values_categories[] = 0;
|
102 |
+
?>
|
103 |
+
<tr class="form-field form-required">
|
104 |
+
<th scope="row">
|
105 |
+
<label> <?php _ex('Apply to category', 'fees admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
106 |
+
</th>
|
107 |
+
<td>
|
108 |
+
<select name="fee[categories][categories][]" multiple="multiple" size="10">
|
109 |
+
<option value="0" <?php echo in_array(0, $post_values_categories) || empty($post_values_categories) ? 'selected="selected"' : ''; ?>><?php _ex('* All Categories *', 'fees admin', 'WPBDM'); ?></option>
|
110 |
+
<?php
|
111 |
+
$directory_categories = wpbdp_categories_list();
|
112 |
+
|
113 |
+
foreach ($directory_categories as &$dir_category) {
|
114 |
+
echo _wpbdp_render_category($dir_category, $post_values_categories);
|
115 |
+
}
|
116 |
+
?>
|
117 |
+
</select>
|
118 |
+
</td>
|
119 |
+
</tr>
|
120 |
+
</table>
|
121 |
+
|
122 |
+
<?php if ( $fee_extra_settings ): ?>
|
123 |
+
<div class="extra-settings">
|
124 |
+
<?php echo $fee_extra_settings; ?>
|
125 |
+
</div>
|
126 |
+
<?php endif; ?>
|
127 |
+
|
128 |
+
<?php if ($fee): ?>
|
129 |
+
<?php echo submit_button(_x('Update Fee', 'fees admin', 'WPBDM')); ?>
|
130 |
+
<?php else: ?>
|
131 |
+
<?php echo submit_button(_x('Add Fee', 'fees admin', 'WPBDM')); ?>
|
132 |
+
<?php endif; ?>
|
133 |
+
</form>
|
134 |
+
|
135 |
+
<?php
|
136 |
+
echo wpbdp_admin_footer();
|
137 |
+
?>
|
admin/templates/fees-confirm-delete.tpl.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(_x('Delete Listing Fee', 'fees admin', 'WPBDM'));
|
3 |
+
?>
|
4 |
+
|
5 |
+
<p>
|
6 |
+
<?php echo sprintf(_x('Are you sure you want to delete the "%s" fee?', 'fees admin', 'WPBDM'), $fee->label); ?>
|
7 |
+
</p>
|
8 |
+
|
9 |
+
<form action="" method="POST">
|
10 |
+
<input type="hidden" name="id" value="<?php echo $fee->id; ?>" />
|
11 |
+
<input type="hidden" name="doit" value="1" />
|
12 |
+
<?php submit_button(_x('Delete Fee', 'fee admin', 'WPBDM'), 'delete'); ?>
|
13 |
+
</form>
|
14 |
+
|
15 |
+
<?php
|
16 |
+
echo wpbdp_admin_footer();
|
17 |
+
?>
|
admin/templates/fees.tpl.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(null, 'admin-fees', wpbdp_get_option('payments-on') ? array(
|
3 |
+
array(_x('Add New Listing Fee', 'fees admin', 'WPBDM'), esc_url(add_query_arg('action', 'addfee'))),
|
4 |
+
) : null);
|
5 |
+
?>
|
6 |
+
<?php wpbdp_admin_notices(); ?>
|
7 |
+
|
8 |
+
<?php if (!wpbdp_get_option('payments-on')): ?>
|
9 |
+
<div class="wpbdp-note"><p>
|
10 |
+
<?php _ex('Payments are currently turned off.', 'fees admin', 'WPBDM' ); ?><br />
|
11 |
+
<?php echo str_replace( '<a>',
|
12 |
+
'<a href="' . admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=payment' ) . '">',
|
13 |
+
_x( 'To manage fees you need to go to the <a>Manage Options - Payment</a> page and check the box next to \'Turn On Payments\' under \'Payment Settings\'.',
|
14 |
+
'fees admin',
|
15 |
+
'WPBDM' ) ); ?></p>
|
16 |
+
</div>
|
17 |
+
<?php else: ?>
|
18 |
+
<div class="fees-order">
|
19 |
+
<form>
|
20 |
+
<input type="hidden" name="action" value="wpbdp-admin-fees-set-order" />
|
21 |
+
<?php wp_nonce_field( 'change fees order' ); ?>
|
22 |
+
<b><?php _ex( 'Order fees on the frontend by:', 'fees admin', 'WPBDM' ); ?></b><br />
|
23 |
+
<select name="fee_order[method]">
|
24 |
+
<?php foreach ( $order_options as $k => $l ): ?>
|
25 |
+
<option value="<?php echo $k; ?>" <?php echo ( $k == $current_order['method'] ) ? 'selected="selected"' : ''; ?> ><?php echo $l; ?></option>
|
26 |
+
<?php endforeach; ?>
|
27 |
+
</select>
|
28 |
+
|
29 |
+
<select name="fee_order[order]" style="<?php echo ( 'custom' == $current_order['method'] ) ? 'display: none;' : ''; ?>">
|
30 |
+
<?php foreach ( array( 'asc' => _x( '↑ Ascending', 'fees admin', 'WPBDM' ), 'desc' => _x( '↓ Descending', 'fees admin', 'WPBDM' ) ) as $o => $l ): ?>
|
31 |
+
<option value="<?php echo $o; ?>" <?php echo ( $o == $current_order['order'] ) ? 'selected="selected"' : ''; ?> ><?php echo $l; ?></option>
|
32 |
+
<?php endforeach; ?>
|
33 |
+
</select>
|
34 |
+
|
35 |
+
<?php if ( 'custom' == $current_order['method'] ): ?>
|
36 |
+
<span><?php _ex( 'Drag and drop to re-order fees.', 'fees admin', 'WPBDM' ); ?></span>
|
37 |
+
<?php endif; ?>
|
38 |
+
|
39 |
+
</form>
|
40 |
+
</div>
|
41 |
+
|
42 |
+
<?php $table->views(); ?>
|
43 |
+
<?php $table->display(); ?>
|
44 |
+
|
45 |
+
<hr />
|
46 |
+
<?php
|
47 |
+
$modules = array(
|
48 |
+
array( 'paypal-gateway-module', _x( 'PayPal Gateway Module', 'admin sidebar', 'WPBDM' ), 'PayPal' ),
|
49 |
+
array( '2checkout-gateway-module', _x( '2Checkout Gateway Module', 'admin sidebar', 'WPBDM' ), '2Checkout' ),
|
50 |
+
array( 'payfast-payment-module', _x( 'PayFast Payment Module', 'admin sidebar', 'WPBDM' ), 'PayFast' ),
|
51 |
+
array( 'stripe-payment-module', _x( 'Stripe Payment Module', 'admin sidebar', 'WPBDM' ), 'Stripe' )
|
52 |
+
);
|
53 |
+
|
54 |
+
global $wpbdp;
|
55 |
+
?>
|
56 |
+
<?php if ( ! $wpbdp->payments->payments_possible() ): ?>
|
57 |
+
<p><?php _ex("It does not appear you have any of the payment gateway modules installed. You need to purchase a payment gateway module in order to charge a fee for listings. To purchase payment gateways use the buttons below or visit", 'admin templates', "WPBDM"); ?></p>
|
58 |
+
<p><a href="http://businessdirectoryplugin.com/premium-modules/" target="_blank">http://businessdirectoryplugin.com/premium-modules/</a></p>
|
59 |
+
<?php endif; ?>
|
60 |
+
|
61 |
+
<div class="purchase-gateways cf">
|
62 |
+
<?php
|
63 |
+
foreach ( $modules as $mod_info ):
|
64 |
+
?>
|
65 |
+
<div class="gateway <?php echo $mod_info[0]; ?> <?php echo $wpbdp->has_module( $mod_info[0] ) ? 'installed' : ''; ?>">
|
66 |
+
<a href="http://businessdirectoryplugin.com/downloads/<?php echo $mod_info[0]; ?>/?ref=wp" target="_blank">
|
67 |
+
<img src="<?php echo WPBDP_URL; ?>admin/resources/<?php echo $mod_info[0]; ?>.png" class="gateway-logo"><br />
|
68 |
+
<a href="http://">
|
69 |
+
</a>
|
70 |
+
<?php if ( $wpbdp->has_module( $mod_info[0] ) ): ?>
|
71 |
+
<a href="http://businessdirectoryplugin.com/downloads/<?php echo $mod_info[0]; ?>/?ref=wp"><?php echo $mod_info[1]; ?></a><br />
|
72 |
+
<span class="check-mark">✓</span> <?php _ex( 'Already installed.', 'admin templates', 'WPBDM' ); ?>
|
73 |
+
<?php else: ?>
|
74 |
+
<?php echo str_replace(
|
75 |
+
'<a>',
|
76 |
+
'<a href="http://businessdirectoryplugin.com/downloads/' . $mod_info[0] . '/?ref=wp" target="_blank">',
|
77 |
+
sprintf( _x( 'You can buy the <a>%s</a> to add <a>%s</a> as a payment option for your users.',
|
78 |
+
'admin templates',
|
79 |
+
'WPBDM' ), $mod_info[1], $mod_info[2] )
|
80 |
+
); ?>
|
81 |
+
<a href="http://businessdirectoryplugin.com/downloads/<?php echo $mod_info[0]; ?>/?ref=wp" target="_blank" class="price">$49.99</a>
|
82 |
+
<?php endif; ?>
|
83 |
+
</div>
|
84 |
+
<?php endforeach; ?>
|
85 |
+
</div>
|
86 |
+
|
87 |
+
<?php endif; ?>
|
88 |
+
|
89 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/form-fields-addoredit.tpl.php
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php echo wpbdp_admin_header( _x( 'Add Form Field', 'form-fields admin', 'WPBDM' ) ); ?>
|
2 |
+
<?php wpbdp_admin_notices(); ?>
|
3 |
+
|
4 |
+
<form id="wpbdp-formfield-form" action="" method="post">
|
5 |
+
<input type="hidden" name="field[id]" value="<?php echo $field->get_id(); ?>" />
|
6 |
+
<input type="hidden" name="field[weight]" value="<?php echo $field->get_weight(); ?>" />
|
7 |
+
|
8 |
+
<table class="form-table">
|
9 |
+
<tbody>
|
10 |
+
<!-- association -->
|
11 |
+
<tr>
|
12 |
+
<th scope="row">
|
13 |
+
<label> <?php _ex('Field Association', 'form-fields admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
14 |
+
</th>
|
15 |
+
<td>
|
16 |
+
<?php $field_association_info = $field_associations[ $field->get_association() ]; ?>
|
17 |
+
<?php if ( in_array( 'private', $field_association_info->flags, true ) ): ?>
|
18 |
+
<select name="field[association]" id="field-association">
|
19 |
+
<option value="<?php echo $field_association_info->id; ?>"><?php echo $field_association_info->label; ?></option>
|
20 |
+
</select>
|
21 |
+
<?php else: ?>
|
22 |
+
<select name="field[association]" id="field-association">
|
23 |
+
<?php foreach ( $field_associations as &$association ): ?>
|
24 |
+
<?php if ( in_array( 'private', $association->flags, true ) ) continue; ?>
|
25 |
+
<option value="<?php echo $association->id; ?>" <?php echo $field->get_association() == $association->id ? ' selected="selected"' : ''; ?> ><?php echo $association->label; ?></option>
|
26 |
+
<?php endforeach; ?>
|
27 |
+
</select>
|
28 |
+
<?php endif; ?>
|
29 |
+
</td>
|
30 |
+
</tr>
|
31 |
+
|
32 |
+
<!-- field type -->
|
33 |
+
<tr class="form-field form-required">
|
34 |
+
<th scope="row">
|
35 |
+
<label> <?php _ex('Field Type', 'form-fields admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
36 |
+
</th>
|
37 |
+
<td>
|
38 |
+
<?php if ( 'custom' === $field->get_association() ): ?>
|
39 |
+
<select name="field[field_type]" id="field-type">
|
40 |
+
<option value="<?php echo $field->get_field_type_id(); ?>"><?php echo $field->get_field_type()->get_name(); ?></option>
|
41 |
+
</select>
|
42 |
+
<?php else: ?>
|
43 |
+
<select name="field[field_type]" id="field-type">
|
44 |
+
<?php foreach ( $field_types as $key => &$field_type ) : ?>
|
45 |
+
<?php if ( !in_array( $field->get_association(), $field_type->get_supported_associations() ) ): ?>
|
46 |
+
<option value="<?php echo $key; ?>" disabled="disabled"><?php echo $field_type->get_name(); ?></option>
|
47 |
+
<?php else: ?>
|
48 |
+
<option value="<?php echo $key; ?>" <?php echo $field->get_field_type() == $field_type ? 'selected="true"' : ''; ?>><?php echo $field_type->get_name(); ?></option>
|
49 |
+
<?php endif; ?>
|
50 |
+
<?php endforeach; ?>
|
51 |
+
</select>
|
52 |
+
<?php endif; ?>
|
53 |
+
</td>
|
54 |
+
</tr>
|
55 |
+
|
56 |
+
<!-- label -->
|
57 |
+
<tr class="form-field form-required">
|
58 |
+
<th scope="row">
|
59 |
+
<label> <?php _ex('Field Label', 'form-fields admin', 'WPBDM'); ?> <span class="description">(required)</span></label>
|
60 |
+
</th>
|
61 |
+
<td>
|
62 |
+
<input name="field[label]" type="text" aria-required="true" value="<?php echo esc_attr( $field->get_label() ); ?>" />
|
63 |
+
</td>
|
64 |
+
</tr>
|
65 |
+
|
66 |
+
<!-- description -->
|
67 |
+
<tr class="form-field">
|
68 |
+
<th scope="row">
|
69 |
+
<label> <?php _ex('Field description', 'form-fields admin', 'WPBDM'); ?> <span class="description">(optional)</span></label>
|
70 |
+
</th>
|
71 |
+
<td>
|
72 |
+
<input name="field[description]" type="text" value="<?php echo esc_attr( $field->get_description() ); ?> " />
|
73 |
+
</td>
|
74 |
+
</tr>
|
75 |
+
</table>
|
76 |
+
|
77 |
+
<!-- field-specific settings -->
|
78 |
+
<?php
|
79 |
+
$field_settings = $field->get_field_type()->render_field_settings( $field, $field->get_association() );
|
80 |
+
ob_start();
|
81 |
+
do_action_ref_array( 'wpbdp_form_field_settings', array( &$field, $field->get_association() ) );
|
82 |
+
$field_settings .= ob_get_contents();
|
83 |
+
ob_end_clean();
|
84 |
+
?>
|
85 |
+
<div id="wpbdp-fieldsettings" style="<?php echo $field_settings ? '' : 'display: none;'; ?>">
|
86 |
+
<h3><?php _ex('Field-specific settings', 'form-fields admin', 'WPBDM'); ?></h3>
|
87 |
+
<div id="wpbdp-fieldsettings-html">
|
88 |
+
<?php echo $field_settings; ?>
|
89 |
+
</div>
|
90 |
+
</div>
|
91 |
+
<!-- /field-specific settings -->
|
92 |
+
|
93 |
+
<!-- validation -->
|
94 |
+
<?php if ( ! $field->has_behavior_flag( 'no-validation' ) ): ?>
|
95 |
+
<h3><?php _ex('Field validation options', 'form-fields admin', 'WPBDM'); ?></h3>
|
96 |
+
<table class="form-table">
|
97 |
+
<tr>
|
98 |
+
<th scope="row">
|
99 |
+
<label> <?php _ex('Field Validator', 'form-fields admin', 'WPBDM'); ?></label>
|
100 |
+
</th>
|
101 |
+
<td>
|
102 |
+
<select name="field[validators][]" id="field-validator">
|
103 |
+
<option value=""><?php _ex('No validation', 'form-fields admin', 'WPBDM'); ?></label>
|
104 |
+
<?php foreach ( $validators as $key => $name): ?>
|
105 |
+
<option value="<?php echo $key; ?>" <?php echo in_array( $key, $field->get_validators(), true ) ? 'selected="selected"' : ''; ?>><?php echo $name; ?></option>
|
106 |
+
<?php endforeach; ?>
|
107 |
+
</select>
|
108 |
+
</td>
|
109 |
+
</tr>
|
110 |
+
<tr>
|
111 |
+
<th scope="row">
|
112 |
+
<label> <?php _ex('Is field required?', 'form-fields admin', 'WPBDM'); ?></label>
|
113 |
+
</th>
|
114 |
+
<td>
|
115 |
+
<label>
|
116 |
+
<input name="field[validators][]"
|
117 |
+
value="required"
|
118 |
+
type="checkbox" <?php echo $field->is_required() ? 'checked="checked"' : ''; ?>/> <?php _ex('This field is required.', 'form-fields admin', 'WPBDM'); ?>
|
119 |
+
</label>
|
120 |
+
</td>
|
121 |
+
</tr>
|
122 |
+
</table>
|
123 |
+
<?php endif; ?>
|
124 |
+
|
125 |
+
<!-- display options -->
|
126 |
+
<h3><?php _ex('Field display options', 'form-fields admin', 'WPBDM'); ?></h3>
|
127 |
+
<table class="form-table">
|
128 |
+
<tr>
|
129 |
+
<th scope="row">
|
130 |
+
<label> <?php _ex('Show this value in excerpt view?', 'form-fields admin', 'WPBDM'); ?></label>
|
131 |
+
</th>
|
132 |
+
<td>
|
133 |
+
<label>
|
134 |
+
<input name="field[display_flags][]"
|
135 |
+
value="excerpt"
|
136 |
+
type="checkbox" <?php echo $field->display_in( 'excerpt') ? 'checked="checked"' : ''; ?>/> <?php _ex('Display this value in post excerpt view.', 'form-fields admin', 'WPBDM'); ?>
|
137 |
+
</label>
|
138 |
+
</td>
|
139 |
+
</tr>
|
140 |
+
<tr>
|
141 |
+
<th scope="row">
|
142 |
+
<label> <?php _ex('Show this value in listing view?', 'form-fields admin', 'WPBDM'); ?></label>
|
143 |
+
</th>
|
144 |
+
<td>
|
145 |
+
<label>
|
146 |
+
<input name="field[display_flags][]"
|
147 |
+
value="listing"
|
148 |
+
type="checkbox" <?php echo $field->display_in( 'listing' ) ? 'checked="checked"' : ''; ?>/> <?php _ex('Display this value in the listing view.', 'form-fields admin', 'WPBDM'); ?>
|
149 |
+
</label>
|
150 |
+
</td>
|
151 |
+
</tr>
|
152 |
+
<tr>
|
153 |
+
<th scope="row">
|
154 |
+
<label> <?php _ex('Include this field in the search form?', 'form-fields admin', 'WPBDM'); ?></label>
|
155 |
+
</th>
|
156 |
+
<td>
|
157 |
+
<label>
|
158 |
+
<input name="field[display_flags][]"
|
159 |
+
value="search"
|
160 |
+
type="checkbox" <?php echo $field->display_in( 'search' ) ? 'checked="checked"' : ''; ?>/> <?php _ex('Include this field in the search form.', 'form-fields admin', 'WPBDM'); ?>
|
161 |
+
</label>
|
162 |
+
</td>
|
163 |
+
</tr>
|
164 |
+
<tr>
|
165 |
+
<th scope="row">
|
166 |
+
<label> <?php _ex('Hide this field\'s label?', 'form-fields admin', 'WPBDM'); ?></label>
|
167 |
+
</th>
|
168 |
+
<td>
|
169 |
+
<label>
|
170 |
+
<input name="field[display_flags][]"
|
171 |
+
value="nolabel"
|
172 |
+
type="checkbox" <?php echo $field->has_display_flag( 'nolabel' ) ? 'checked="checked"' : ''; ?>/> <?php _ex('Hide this field\'s label when displaying it.', 'form-fields admin', 'WPBDM'); ?>
|
173 |
+
</label>
|
174 |
+
</td>
|
175 |
+
</tr>
|
176 |
+
</table>
|
177 |
+
|
178 |
+
<?php if ( $field->get_id() ): ?>
|
179 |
+
<?php echo submit_button(_x('Update Field', 'form-fields admin', 'WPBDM')); ?>
|
180 |
+
<?php else: ?>
|
181 |
+
<?php echo submit_button(_x('Add Field', 'form-fields admin', 'WPBDM')); ?>
|
182 |
+
<?php endif; ?>
|
183 |
+
</form>
|
184 |
+
|
185 |
+
<script type="text/javascript">
|
186 |
+
jQuery(document).ready(function(){
|
187 |
+
WPBDP_associations_fieldtypes = <?php echo json_encode( $association_field_types ); ?>
|
188 |
+
});
|
189 |
+
</script>
|
190 |
+
|
191 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/form-fields-confirm-delete.tpl.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(_x('Delete Form Field', 'form-fields admin', 'WPBDM'));
|
3 |
+
?>
|
4 |
+
|
5 |
+
<p>
|
6 |
+
<?php echo sprintf(_x('Are you sure you want to delete the "%s" field?', 'form-fields admin', 'WPBDM'), $field->get_label()); ?>
|
7 |
+
</p>
|
8 |
+
|
9 |
+
<form action="" method="POST">
|
10 |
+
<input type="hidden" name="id" value="<?php echo $field->get_id(); ?>" />
|
11 |
+
<input type="hidden" name="doit" value="1" />
|
12 |
+
<?php submit_button(_x('Delete Field', 'form-fields admin', 'WPBDM'), 'delete'); ?>
|
13 |
+
</form>
|
14 |
+
|
15 |
+
<?php
|
16 |
+
echo wpbdp_admin_footer();
|
17 |
+
?>
|
admin/templates/form-fields.tpl.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(null, null, array(
|
3 |
+
array(_x('Add New Form Field', 'form-fields admin', 'WPBDM'), esc_url(add_query_arg('action', 'addfield'))),
|
4 |
+
array(_x('Preview Form', 'form-fields admin', 'WPBDM'), esc_url(add_query_arg('action', 'previewform'))),
|
5 |
+
));
|
6 |
+
?>
|
7 |
+
<?php wpbdp_admin_notices(); ?>
|
8 |
+
|
9 |
+
<?php _ex('Make changes to your existing form fields.', 'form-fields admin', 'WPBDM'); ?>
|
10 |
+
|
11 |
+
<?php $table->views(); ?>
|
12 |
+
<?php $table->display(); ?>
|
13 |
+
|
14 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/header.tpl.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap wpbdp-admin <?php echo isset($page_id) ? 'wpbdp-page-' . $page_id : ''; ?>">
|
2 |
+
<div id="icon-edit-pages" class="icon32"></div>
|
3 |
+
<h2>
|
4 |
+
<?php echo isset($page_title) ? $page_title : __("Business Directory Plugin","WPBDM"); ?>
|
5 |
+
|
6 |
+
<?php if ($h2items): ?>
|
7 |
+
<?php foreach ($h2items as $item): ?>
|
8 |
+
<a href="<?php echo $item[1]; ?>" class="add-new-h2"><?php echo $item[0]; ?></a>
|
9 |
+
<?php endforeach; ?>
|
10 |
+
<?php endif; ?>
|
11 |
+
</h2>
|
12 |
+
|
13 |
+
<?php echo $sidebar = $sidebar ? wpbdp_admin_sidebar() : false; ?>
|
14 |
+
|
15 |
+
<div class="wpbdp-admin-content <?php echo !empty($sidebar) ? 'with-sidebar' : 'without-sidebar'; ?>">
|
16 |
+
<!-- <div class="postbox"> -->
|
admin/templates/home.tpl.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php echo wpbdp_admin_header(); ?>
|
2 |
+
|
3 |
+
<div class="wpbdp-note welcome-message">
|
4 |
+
<h4><?php printf( _x( 'Welcome to Business Directory Plugin. You are using %s.', 'admin home', 'WPBDM' ), '<span class="version">' . wpbdp_get_version() . '</span>' ); ?></h4>
|
5 |
+
<p><?php _ex( 'Thanks for choosing us. There\'s a lot you probably want to get done, so let\'s jump right in!',
|
6 |
+
'admin home',
|
7 |
+
'WPBDM' ); ?></p>
|
8 |
+
<ul>
|
9 |
+
<li>
|
10 |
+
<?php echo str_replace( '<a>', '<a href="http://businessdirectoryplugin.com/docs" target="_blank">',
|
11 |
+
_x( 'Our complete documentation is <a>here</a> which we encourage you to use while setting things up.', 'admin home', 'WPBDM' ) ); ?>
|
12 |
+
<li>
|
13 |
+
<?php echo str_replace( '<a>', '<a href="http://businessdirectoryplugin.com/quick-start-guide/" target="_blank">',
|
14 |
+
_x( 'We have some quick-start scenarios that you will find useful regarding setup and configuration <a>here</a>.', 'admin home', 'WPBDM' ) ); ?>
|
15 |
+
</li>
|
16 |
+
<li>
|
17 |
+
<?php echo str_replace( '<a>', '<a href="http://businessdirectoryplugin.com/support-forum/" target="_blank">',
|
18 |
+
_x( 'If you have questions, please post a comment on <a>support forum</a> and we\'ll answer it within 24 hours most days.', 'admin home', 'WPBDM' ) ); ?>
|
19 |
+
|
20 |
+
</ul>
|
21 |
+
</div>
|
22 |
+
|
23 |
+
<ul class="shortcuts">
|
24 |
+
<li>
|
25 |
+
<a href="<?php echo admin_url( 'admin.php?page=wpbdp_admin_settings' ); ?>" class="button"><?php _e( 'Configure/Manage Options', 'WPBDM' ); ?></a>
|
26 |
+
</li>
|
27 |
+
<li>
|
28 |
+
<a href="<?php echo admin_url( 'admin.php?page=wpbdp_admin_formfields' ); ?>" class="button"><?php _e( 'Setup/Manage Form Fields', 'WPBDM' ); ?></a>
|
29 |
+
</li>
|
30 |
+
<li>
|
31 |
+
<a href="<?php echo admin_url( 'admin.php?page=wpbdp_admin_fees' ); ?>" class="button"><?php echo _e( 'Setup/Manage Fees', 'WPBDM' ); ?></a>
|
32 |
+
</li>
|
33 |
+
<li class="clear"></li>
|
34 |
+
|
35 |
+
<?php if ( wpbdp_get_option( 'featured-on' ) ): ?>
|
36 |
+
<li>
|
37 |
+
<a href="<?php echo admin_url( sprintf( 'edit.php?post_type=%s&wpbdmfilter=pendingupgrade', WPBDP_POST_TYPE ) ); ?>" class="button"><?php _e( 'Featured Listings Pending Upgrade', 'WPBDM' ); ?></a>
|
38 |
+
</li>
|
39 |
+
<?php endif; ?>
|
40 |
+
|
41 |
+
|
42 |
+
<?php if ( wpbdp_get_option( 'payments-on' ) ): ?>
|
43 |
+
<li>
|
44 |
+
<a href="<?php echo admin_url( sprintf( 'edit.php?post_type=%s&wpbdmfilter=unpaid', WPBDP_POST_TYPE ) ) ?>" class="button"><?php _e( 'Manage Paid Listings', 'WPBDM' ); ?></a>
|
45 |
+
</li>
|
46 |
+
<?php endif; ?>
|
47 |
+
</ul>
|
48 |
+
|
49 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/listing-change-fee.tpl.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="listing-fee-change">
|
2 |
+
<h2>
|
3 |
+
<?php _ex( 'Listing Fee Selection', 'admin listing fee', 'WPBDM' ); ?>
|
4 |
+
</h2>
|
5 |
+
<p><?php printf( _x( 'Select a fee plan to be used for this listing in the "%s" category.', 'admin listing fee', 'WPBDM' ), $category->name ); ?></p>
|
6 |
+
|
7 |
+
<div class="fee-selection">
|
8 |
+
<?php foreach ( $fees as &$f ): ?>
|
9 |
+
<div class="fee">
|
10 |
+
<?php if ( $category->fee_id == $f->id ): ?>
|
11 |
+
<span class="tag"><?php _ex( 'Current', 'admin listing fee', 'WPBDM' ); ?></span>
|
12 |
+
<?php else: ?>
|
13 |
+
<a href="<?php echo add_query_arg( array( 'wpbdmaction' => 'assignfee', 'category_id' => $category->id, 'fee_id' => $f->id ), admin_url( 'post.php?post=' . $listing->get_id() . '&action=edit' ) ); ?>" class="button choose-this">
|
14 |
+
<?php _ex( 'Use this fee', 'admin listing fee', 'WPBDM' ); ?>
|
15 |
+
</a>
|
16 |
+
<?php endif; ?>
|
17 |
+
|
18 |
+
<strong><?php echo $f->label; ?></strong><br />
|
19 |
+
<div class="details">
|
20 |
+
<?php echo wpbdp_format_currency( $f->amount ); ?> •
|
21 |
+
<?php echo sprintf(_nx('%d image', '%d images', $f->images, 'admin infometabox', 'WPBDM'), $f->images); ?> •
|
22 |
+
<?php if ($f->days == 0): ?>
|
23 |
+
<?php _ex('Listing never expires', 'admin infometabox', 'WPBDM'); ?>
|
24 |
+
<?php else: ?>
|
25 |
+
<?php echo sprintf(_nx('%d day', '%d days', $f->days, 'admin infometabox', 'WPBDM'), $f->days); ?>
|
26 |
+
<?php endif; ?>
|
27 |
+
</div>
|
28 |
+
</div>
|
29 |
+
<?php endforeach; ?>
|
30 |
+
</div>
|
31 |
+
</div>
|
admin/templates/listing-metabox-categories.tpl.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Listing category (general & fee information) display.
|
4 |
+
* @since 3.4
|
5 |
+
* @param $categories array The categories (from {@link WPBDP_Listing::get_categories()}).
|
6 |
+
* @param $display array() Optional.
|
7 |
+
* @param $admin_actions array() Optional.
|
8 |
+
*/
|
9 |
+
|
10 |
+
$image_count = count( $listing->get_images() );
|
11 |
+
|
12 |
+
if ( ! isset( $display ) )
|
13 |
+
$display = array( 'fee label', 'fee images', 'expiration' );
|
14 |
+
|
15 |
+
if ( ! isset( $admin_actions ) )
|
16 |
+
$admin_actions = array( 'delete', 'renewal url', 'renewal email', 'change fee' );
|
17 |
+
?>
|
18 |
+
|
19 |
+
<div class="listing-categories">
|
20 |
+
|
21 |
+
<?php if ( ! $categories ): ?>
|
22 |
+
<p><?php _ex( 'No categories on this listing. Please add one to associate fees.', 'admin infometabox', 'WPBDM' ); ?></p>
|
23 |
+
<?php else: ?>
|
24 |
+
<?php foreach ( $categories as &$category ): ?>
|
25 |
+
<div class="listing-category <?php echo $category->expired ? 'expired' : ''; ?> listing-category-<?php echo $category->id; ?>">
|
26 |
+
|
27 |
+
<div class="header">
|
28 |
+
<?php if ( current_user_can( 'administrator' ) ): ?><span class="spinner"></span><?php endif; ?>
|
29 |
+
<span class="category-name"><?php echo $category->name; ?> <?php echo $category->recurring ? ' ' . _x( '(recurring)', 'admin infometabox', 'WPBDM' ) : ''; ?></span>
|
30 |
+
<span class="tag category-status <?php echo $category->status; ?>">
|
31 |
+
<?php
|
32 |
+
switch ( $category->status ):
|
33 |
+
case 'expired':
|
34 |
+
_ex( 'Expired', 'admin infometabox', 'WPBDM' );
|
35 |
+
break;
|
36 |
+
case 'pending':
|
37 |
+
_ex( 'Payment Pending', 'admin infometabox', 'WPBDM' );
|
38 |
+
break;
|
39 |
+
case 'ok':
|
40 |
+
default:
|
41 |
+
_ex( 'OK', 'admin infometabox', 'WPBDM');
|
42 |
+
endswitch;
|
43 |
+
?>
|
44 |
+
</span>
|
45 |
+
</div>
|
46 |
+
<div class="category-details">
|
47 |
+
<dl>
|
48 |
+
<?php if ( in_array( 'fee label', $display, true ) ): ?>
|
49 |
+
<dt><?php _ex('Fee', 'admin infometabox', 'WPBDM'); ?></dt>
|
50 |
+
<dd><?php echo $category->fee->label; ?></dd>
|
51 |
+
<?php endif; ?>
|
52 |
+
|
53 |
+
<?php if ( in_array( 'fee images', $display, true ) ): ?>
|
54 |
+
<dt><?php _ex('# Images', 'admin infometabox', 'WPBDM'); ?></dt>
|
55 |
+
<dd><?php echo min( $image_count, $category->fee_images); ?> / <?php echo $category->fee_images; ?></dd>
|
56 |
+
<?php endif; // ?>
|
57 |
+
|
58 |
+
<?php if ( in_array( 'expiration', $display, true ) ): ?>
|
59 |
+
<?php if ( 'pending' != $category->status ): ?>
|
60 |
+
<dt>
|
61 |
+
<?php if ( $category->expired ): ?>
|
62 |
+
<?php _ex('Expired on', 'admin infometabox', 'WPBDM'); ?>
|
63 |
+
<?php else: ?>
|
64 |
+
<?php _ex('Expires on', 'admin infometabox', 'WPBDM'); ?>
|
65 |
+
<?php endif; ?>
|
66 |
+
</dt>
|
67 |
+
<dd class="expiration-date-info">
|
68 |
+
<span class="expiration-date">
|
69 |
+
<?php echo $category->expires_on ? date_i18n( get_option( 'date_format' ), strtotime( $category->expires_on ) ) : _x( 'never', 'admin infometabox', 'WPBDM' ); ?>
|
70 |
+
</span>
|
71 |
+
<?php if ( current_user_can( 'administrator' ) ): ?>
|
72 |
+
<a href="#" class="expiration-change-link" title="<?php _ex( 'Click to manually change expiration date.', 'admin infometabox', 'WPBDM' ); ?>"
|
73 |
+
data-renewal_id="<?php echo $category->renewal_id; ?>"
|
74 |
+
data-date="<?php echo date('Y-m-d', strtotime( $category->expires_on ) ); ?>"><?php _ex( 'Edit', 'admin infometabox', 'WPBDM' ); ?></a>
|
75 |
+
<div class="datepicker renewal-<?php echo $category->renewal_id; ?>"></div>
|
76 |
+
<?php endif; ?>
|
77 |
+
</dd>
|
78 |
+
<?php endif; ?>
|
79 |
+
<?php endif; ?>
|
80 |
+
</dl>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<?php if ( $admin_actions && current_user_can( 'administrator' ) ): ?>
|
84 |
+
<ul class="admin-actions">
|
85 |
+
<?php if ( 'pending' == $category->status ) : ?>
|
86 |
+
<li><a href="#" class="payment-details-link" data-id="<?php echo $category->payment_id; ?>"><?php _ex( 'See payment info', 'admin infometabox', 'WPBDM' ); ?></a></li>
|
87 |
+
<?php else: ?>
|
88 |
+
|
89 |
+
<?php if ( in_array( 'renewal url', $admin_actions, true ) ): ?>
|
90 |
+
<li>
|
91 |
+
<a href="#" onclick="window.prompt('<?php _ex( 'Renewal URL (copy & paste)', 'admin infometabox', 'WPBDM' ); ?>', '<?php echo $listing->get_renewal_url( $category->id ); ?>'); return false;"><?php _ex( 'Show renewal link', 'admin infometabox', 'WPBDM' ); ?></a>
|
92 |
+
</li>
|
93 |
+
<?php endif; ?>
|
94 |
+
|
95 |
+
<?php if ( in_array( 'renewal email', $admin_actions, true ) ): ?>
|
96 |
+
<li>
|
97 |
+
<a href="<?php echo add_query_arg( array( 'wpbdmaction' => 'send-renewal-email', 'renewal_id' => $category->renewal_id ) ); ?>">
|
98 |
+
<?php _ex( 'Send renewal e-mail to user', 'admin infometabox', 'WPBDM' ); ?>
|
99 |
+
</a>
|
100 |
+
</li>
|
101 |
+
<?php endif; ?>
|
102 |
+
|
103 |
+
<?php if ( in_array( 'change fee', $admin_actions, true ) ): ?>
|
104 |
+
<li>
|
105 |
+
<a href="#" data-renewal="<?php echo $category->renewal_id; ?>" class="category-change-fee">
|
106 |
+
<?php ( $category->expired ? _ex( 'Renew manually...', 'admin infometabox', 'WPBDM' ) : _ex('Change fee...', 'admin infometabox', 'WPBDM') ); ?>
|
107 |
+
</a>
|
108 |
+
</li>
|
109 |
+
<?php endif; ?>
|
110 |
+
|
111 |
+
<?php if ( in_array( 'delete', $admin_actions, true ) ): ?>
|
112 |
+
<li class="delete">
|
113 |
+
<a href="#" data-listing="<?php echo $listing->get_id(); ?>" data-category="<?php echo $category->id; ?>" class="category-delete">
|
114 |
+
<?php _ex('Remove category', 'admin infometabox', 'WPBDM'); ?>
|
115 |
+
</a>
|
116 |
+
</li>
|
117 |
+
<?php endif; ?>
|
118 |
+
|
119 |
+
<?php endif; ?>
|
120 |
+
</ul>
|
121 |
+
<?php endif; ?>
|
122 |
+
|
123 |
+
</div>
|
124 |
+
<?php endforeach; ?>
|
125 |
+
<?php endif; ?>
|
126 |
+
</div>
|
admin/templates/listing-metabox-fees.tpl.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<strong><?php _ex('Fee Information', 'admin infometabox', 'WPBDM'); ?></strong>
|
2 |
+
|
3 |
+
<?php _ex('Payment Mode:', 'admin infometabox', 'WPBDM'); ?> <?php echo wpbdp_payments_api()->payments_possible() ? _x('Paid', 'admin infometabox', 'WPBDM') : _x('Free', 'admin infometabox', 'WPBDM'); ?><br />
|
4 |
+
<?php
|
5 |
+
if (current_user_can('administrator')) {
|
6 |
+
echo sprintf(_x('To change your payment mode, go to <a href="%s">Payment Settings</a>.', 'admin infometabox', 'WPBDM'),
|
7 |
+
admin_url('admin.php?page=wpbdp_admin_settings&groupid=payment') );
|
8 |
+
}
|
9 |
+
?>
|
10 |
+
|
11 |
+
<?php if (!wpbdp_payments_api()->payments_possible() && current_user_can('administrator')): ?>
|
12 |
+
<p><i><?php _ex('Note: In Free mode, the fee plans will always be set to "Free Listing" below.', 'admin infometabox', 'WPBDM'); ?></i></p>
|
13 |
+
<?php endif; ?>
|
14 |
+
|
15 |
+
<?php
|
16 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-metabox-categories.tpl.php', array(
|
17 |
+
'categories' => $categories,
|
18 |
+
'listing' => $listing ) );
|
19 |
+
?>
|
20 |
+
|
21 |
+
<?php if ( $listing->get_categories( 'expired' ) ): ?>
|
22 |
+
<a href="<?php echo add_query_arg( 'wpbdmaction', 'renewlisting' ); ?>" class="button-primary button"><?php _ex( 'Renew listing in all expired categories', 'admin infometabox', 'WPBDM'); ?></a>
|
23 |
+
<?php endif; ?>
|
admin/templates/listing-metabox-feesummary.tpl.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p><strong><?php _ex('Categories for this listing', 'admin infometabox', 'WPBDM'); ?></strong></p>
|
2 |
+
|
3 |
+
<?php
|
4 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/listing-metabox-categories.tpl.php', array(
|
5 |
+
'categories' => $categories,
|
6 |
+
'listing' => $listing,
|
7 |
+
'display' => array( 'expiration' ),
|
8 |
+
'admin_actions' => array( 'delete', 'renewal url', 'renewal email' ) ) );
|
9 |
+
?>
|
10 |
+
|
11 |
+
<?php if ( $listing->get_categories( 'expired' ) ): ?>
|
12 |
+
<a href="<?php echo add_query_arg( 'wpbdmaction', 'renewlisting' ); ?>" class="button-primary button"><?php _ex( 'Renew listing in all expired categories', 'admin infometabox', 'WPBDM'); ?></a>
|
13 |
+
<?php endif; ?>
|
admin/templates/listing-metabox-transactions.tpl.php
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$_transaction_types = array(
|
3 |
+
'initial' => _x('Initial Payment', 'admin infometabox', 'WPBDM'),
|
4 |
+
'edit' => _x('Listing Edit', 'admin infometabox', 'WPBDM'),
|
5 |
+
'renewal' => _x('Listing Renewal', 'admin infometabox', 'WPBDM'),
|
6 |
+
'upgrade-to-sticky' => _x('Upgrade to sticky', 'admin infometabox', 'WPBDM'),
|
7 |
+
);
|
8 |
+
|
9 |
+
?>
|
10 |
+
<strong><?php _ex('Payments History', 'admin', 'WPBDM'); ?></strong>
|
11 |
+
<?php if ( current_user_can( 'administrator' ) ): ?>
|
12 |
+
<p><?php _ex( 'Click a payment to see the details or approve/reject the transaction.', 'admin listing metabox', 'WPBDM' ); ?></p>
|
13 |
+
<?php endif; ?>
|
14 |
+
|
15 |
+
<?php if ( ! $payments ): ?>
|
16 |
+
<p><?php _ex( 'There are no transactions associated to this listing.', 'listing metabox', 'WPBDM' ); ?></p>
|
17 |
+
<?php else: ?>
|
18 |
+
<table class="payments-list">
|
19 |
+
<?php foreach ( $payments as &$payment ): ?>
|
20 |
+
<tr class="payment <?php echo $payment->get_status(); ?>">
|
21 |
+
<td class="date">
|
22 |
+
<a href="#" class="payment-details-link" data-id="<?php echo $payment->get_id(); ?>">
|
23 |
+
<?php echo date_i18n( get_option( 'date_format' ), strtotime( $payment->get_created_on() ) ); ?>
|
24 |
+
</a>
|
25 |
+
</td>
|
26 |
+
<td class="total">
|
27 |
+
<a href="#" class="payment-details-link" data-id="<?php echo $payment->get_id(); ?>">
|
28 |
+
<?php echo wpbdp_format_currency( $payment->get_total(), 2, $payment->get_currency_code() ); ?>
|
29 |
+
</a></td>
|
30 |
+
<td class="status"><span class="tag paymentstatus <?php echo $payment->get_status(); ?>"><?php echo $payment->get_status(); ?></span></td>
|
31 |
+
</tr>
|
32 |
+
<?php endforeach; ?>
|
33 |
+
</table>
|
34 |
+
<?php endif; ?>
|
admin/templates/payment-details.tpl.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Payment details template.
|
4 |
+
* @since 3.4
|
5 |
+
*/
|
6 |
+
?>
|
7 |
+
<div id="wpbdp-payment-details-<?php echo $payment->get_id(); ?>" class="<?php echo $payment->get_status(); ?> wpbdp-payment-details" data-title="<?php echo esc_attr( _x( 'Payment Details', 'admin payments', 'WPBDM' ) ); ?>">
|
8 |
+
<div class="header">
|
9 |
+
<h2><?php printf( _x( 'Payment #%d', 'admin payments', 'WPBDM'), $payment->get_id() ); ?></h2>
|
10 |
+
<span class="date"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $payment->get_created_on() ) ); ?></span>
|
11 |
+
<span class="payment-status tag <?php echo $payment->get_status(); ?>"><?php echo $payment->get_status(); ?></span>
|
12 |
+
</div>
|
13 |
+
|
14 |
+
<div class="details">
|
15 |
+
<dl>
|
16 |
+
<dt><?php echo _ex('Created on', 'admin payments', 'WPBDM'); ?></dt>
|
17 |
+
<dd><?php echo $payment->get_created_on(); ?></dd>
|
18 |
+
|
19 |
+
<dt><?php _ex('Amount', 'admin infometabox', 'WPBDM'); ?></dt>
|
20 |
+
<dd><?php echo wpbdp_format_currency( $payment->get_total(), 2, $payment->get_currency_code() ); ?></dd>
|
21 |
+
|
22 |
+
<dt><?php _ex('Gateway', 'admin infometabox', 'WPBDM'); ?></dt>
|
23 |
+
<dd><?php echo $payment->get_gateway() ? $payment->get_gateway() : '–'; ?></dd>
|
24 |
+
|
25 |
+
<?php if ( $payment->has_been_processed() ): ?>
|
26 |
+
<dt><?php _ex('Processed on', 'admin infometabox', 'WPBDM'); ?></dt>
|
27 |
+
<dd><?php echo $payment->get_processed_on(); ?></dd>
|
28 |
+
<dt><?php _ex('Processed by', 'admin infometabox', 'WPBDM'); ?></dt>
|
29 |
+
<dd><?php echo $payment->get_handler(); ?></dd>
|
30 |
+
<?php endif; ?>
|
31 |
+
</dl>
|
32 |
+
</div>
|
33 |
+
|
34 |
+
<div class="invoice"><?php echo $invoice; ?></div>
|
35 |
+
|
36 |
+
<div class="actions">
|
37 |
+
<?php if ( $payment->is_pending() ): ?>
|
38 |
+
<a href="<?php echo add_query_arg( array( 'wpbdmaction' => 'approvetransaction', 'transaction_id' => $payment->get_id() ),
|
39 |
+
admin_url('post.php?post=' . $payment->get_listing_id() . '&action=edit' ) ); ?>" class="button-primary">
|
40 |
+
<?php _ex('Approve payment', 'admin payments', 'WPBDM'); ?>
|
41 |
+
</a>
|
42 |
+
<a href="<?php echo add_query_arg( array( 'wpbdmaction' => 'rejecttransaction', 'transaction_id' => $payment->get_id() ),
|
43 |
+
admin_url('post.php?post=' . $payment->get_listing_id() . '&action=edit' ) ); ?>" class="button">
|
44 |
+
<?php _ex('Reject payment', 'admin payments', 'WPBDM'); ?>
|
45 |
+
</a>
|
46 |
+
<?php endif; ?>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
+
<?php
|
50 |
+
/*
|
51 |
+
<div class="details">
|
52 |
+
<dl>
|
53 |
+
<dt><?php _ex('Payer Info', 'admin infometabox', 'WPBDM'); ?></dt>
|
54 |
+
<dd>
|
55 |
+
Name: <span class="name"><?php echo $payment->get_payer_info( 'name' ) ? $payment->get_payer_info( 'name' ) : '--'; ?></span><br />
|
56 |
+
Email: <span class="email"><?php echo $payment->get_payer_info( 'email' ) ? $payment->get_payer_info( 'email' ) : '--'; ?></span>
|
57 |
+
</dd>
|
58 |
+
</dl>*/
|
59 |
+
?>
|
admin/templates/settings.tpl.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(__('Business Directory Settings', 'WPBDM'), 'admin-settings');
|
3 |
+
?>
|
4 |
+
<script type="text/javascript">
|
5 |
+
<?php
|
6 |
+
foreach ( $wpbdp_settings->get_dependencies( 'type=requires-true' ) as $s => $data_ ):
|
7 |
+
$parent = array_pop( $data_ );
|
8 |
+
?>
|
9 |
+
WPBDP_Admin.settings.add_requirement( '<?php echo $s; ?>', '<?php echo $parent; ?>', 'boolean-true' );
|
10 |
+
<?php
|
11 |
+
endforeach;
|
12 |
+
?>
|
13 |
+
</script>
|
14 |
+
|
15 |
+
<h3 class="nav-tab-wrapper">
|
16 |
+
<?php if (isset($_REQUEST['settings-updated'])): ?>
|
17 |
+
<div class="updated fade">
|
18 |
+
<p><?php _e('Settings updated.', 'WPBDM'); ?></p>
|
19 |
+
</div>
|
20 |
+
<?php endif; ?>
|
21 |
+
|
22 |
+
<?php foreach($wpbdp_settings->groups as $g): ?>
|
23 |
+
<a class="nav-tab <?php echo $g->slug == wpbdp_getv($_REQUEST, 'groupid', 'general') ? 'nav-tab-active': ''; ?> <?php echo apply_filters( 'wpbdp_settings_group_tab_css', '', $g ); ?>"
|
24 |
+
href="<?php echo add_query_arg('groupid', $g->slug, remove_query_arg('settings-updated')); ?>">
|
25 |
+
<?php echo apply_filters( 'wpbdp_settings_group_tab_name', $g->name, $g ); ?>
|
26 |
+
</a>
|
27 |
+
<?php endforeach; ?>
|
28 |
+
<a class="nav-tab <?php echo wpbdp_getv($_REQUEST, 'groupid') == 'resetdefaults' ? 'nav-tab-active' : ''; ?>"
|
29 |
+
href="<?php echo add_query_arg('groupid', 'resetdefaults', remove_query_arg('settings-updated')); ?>">
|
30 |
+
<?php _e('Reset Defaults', 'WPBDM'); ?>
|
31 |
+
</a>
|
32 |
+
</h3>
|
33 |
+
|
34 |
+
<?php if (wpbdp_getv($_REQUEST, 'groupid', 'general') == 'resetdefaults'): ?>
|
35 |
+
|
36 |
+
<p><?php _e('Use this option if you want to go back to the factory-settings. Please notice that all of your customizations will be lost.', 'WPBDM'); ?></p>
|
37 |
+
<form action="" method="POST">
|
38 |
+
<input type="hidden" name="resetdefaults" value="1" />
|
39 |
+
<?php echo submit_button(__('Reset Defaults', 'WPBDM')); ?>
|
40 |
+
</form>
|
41 |
+
|
42 |
+
<?php else: ?>
|
43 |
+
<?php
|
44 |
+
$group = $wpbdp_settings->groups[wpbdp_getv($_REQUEST, 'groupid', 'general')];
|
45 |
+
?>
|
46 |
+
|
47 |
+
<form action="<?php echo admin_url('options.php'); ?>" method="POST" id="wpbdp-admin-settings">
|
48 |
+
<input type="hidden" name="groupid" value="<?php echo $group->slug; ?>" />
|
49 |
+
<?php if ($group->help_text): ?>
|
50 |
+
<p class="description"><?php echo $group->help_text; ?></p>
|
51 |
+
<?php endif; ?>
|
52 |
+
<?php settings_fields($group->wpslug); ?>
|
53 |
+
<?php do_settings_sections($group->wpslug); ?>
|
54 |
+
<?php echo submit_button(); ?>
|
55 |
+
</form>
|
56 |
+
<?php endif; ?>
|
57 |
+
|
58 |
+
<?php
|
59 |
+
echo wpbdp_admin_footer();
|
60 |
+
?>
|
admin/templates/sidebar.tpl.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$modules = array(
|
3 |
+
array( 'payfast-payment-module', _x( 'PayFast Payment Module', 'admin sidebar', 'WPBDM' ), 'new' ),
|
4 |
+
array( 'stripe-payment-module', _x( 'Stripe Payment Module', 'admin sidebar', 'WPBDM' ), 'new' ),
|
5 |
+
array( 'file-attachments-module', _x( 'File Upload Module', 'admin sidebar', 'WPBDM' ), 'new' ),
|
6 |
+
array( 'featured-levels-module', _x( 'Featured Levels Module', 'admin sidebar', 'WPBDM' ) ),
|
7 |
+
array( 'zip-search-module', _x( 'ZIP Code Search Module', 'admin sidebar', 'WPBDM' ) ),
|
8 |
+
array( 'regions-module', _x( 'Regions Module', 'admin sidebar', 'WPBDM' ) ),
|
9 |
+
array( 'ratings-module', _x( 'Ratings Module', 'admin sidebar', 'WPBDM' ) ),
|
10 |
+
array( 'google-maps-module', _x( 'Google Maps Module', 'admin sidebar', 'WPBDM' ) ),
|
11 |
+
array( 'paypal-gateway-module', _x( 'PayPal Gateway Module', 'admin sidebar', 'WPBDM' ) ),
|
12 |
+
array( '2checkout-gateway-module', _x( '2Checkout Gateway Module', 'admin sidebar', 'WPBDM' ) )
|
13 |
+
);
|
14 |
+
?>
|
15 |
+
<div class="sidebar">
|
16 |
+
<div class="meta-box-sortables metabox-holder ui-sortable" id="side-sortables">
|
17 |
+
<!-- Like this plugin? -->
|
18 |
+
<div class="postbox">
|
19 |
+
<h3 class="hndle"><span><?php _ex( 'Like this plugin?', 'admin sidebar', 'WPBDM'); ?></span></h3>
|
20 |
+
<div class="inside">
|
21 |
+
<p><?php _ex( 'Why not do any or all of the following:', 'admin sidebar', 'WPBDM'); ?></p>
|
22 |
+
<ul>
|
23 |
+
<li class="li_link"><a href="http://wordpress.org/extend/plugins/business-directory-plugin/"><?php _ex( 'Give it a good rating on WordPress.org.', 'admin sidebar', 'WPBDM'); ?></a></li>
|
24 |
+
<li class="li_link"><a href="http://wordpress.org/extend/plugins/business-directory-plugin/"><?php _ex( 'Let other people know that it works with your WordPress setup.', 'admin sidebar', 'WPBDM'); ?></a></li>
|
25 |
+
<li class="li_link"><a href="http://businessdirectoryplugin.com/premium-modules/"><?php _ex( 'Buy a Premium Module', 'admin sidebar', 'WPBDM'); ?></a></li>
|
26 |
+
</ul>
|
27 |
+
</div>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
<!-- Premium modules -->
|
31 |
+
<div class="postbox premium-modules">
|
32 |
+
<h3 class="hndle"><span><?php _ex( 'Get a Premium Module', 'admin sidebar', 'WPBDM'); ?></span></h3>
|
33 |
+
<div class="inside">
|
34 |
+
<ul>
|
35 |
+
<?php foreach ( $modules as $mod_info ): ?>
|
36 |
+
<li class="li_link">
|
37 |
+
<?php if ( isset( $mod_info[2] ) && 'new' == $mod_info[2] ): ?><img src="<?php echo WPBDP_URL; ?>admin/resources/new.gif" /> <?php endif; ?>
|
38 |
+
<a href="http://businessdirectoryplugin.com/downloads/<?php echo $mod_info[0]; ?>/?ref=wp" target="_blank"><?php echo $mod_info[1]; ?></a>
|
39 |
+
</li>
|
40 |
+
<?php endforeach; ?>
|
41 |
+
<li class="li_link"><a href="http://businessdirectoryplugin.com/premium-modules/business-directory-combo-pack/"><?php _ex('Single Site License Combo Pack', 'admin sidebar', 'WPBDM'); ?></a></li>
|
42 |
+
<li class="li_link"><a href="http://businessdirectoryplugin.com/premium-modules/business-directory-combo-pack-multi-site/"><?php _ex('Multi Site License Combo Pack', 'admin sidebar', 'WPBDM'); ?></a></li>
|
43 |
+
</ul>
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
|
47 |
+
<!-- support -->
|
48 |
+
<div class="postbox">
|
49 |
+
<h3 class="hndle"><span><?php _ex('Found a bug? Need support?', 'admin sidebar', 'WPBDM'); ?></span></h3>
|
50 |
+
<div class="inside">
|
51 |
+
<p>
|
52 |
+
<?php echo str_replace( '<a>',
|
53 |
+
'<a href="http://businessdirectoryplugin.com/forums/" target="_blank">',
|
54 |
+
_x( 'If you\'ve found a bug or need support <a>visit the forums!</a>', 'admin sidebar', 'WPBDM' ) ); ?>
|
55 |
+
</p>
|
56 |
+
<p>
|
57 |
+
• <a href="http://businessdirectoryplugin.com/docs/"><?php _ex( 'Full plugin documentation', 'admin sidebar', 'WPBDM' ); ?></a><br />
|
58 |
+
• <a href="http://businessdirectoryplugin.com/quick-start-guide/"><?php _ex( 'Quick Start Guide', 'admin sidebar', 'WPBDM' ); ?></a>
|
59 |
+
</p>
|
60 |
+
</div>
|
61 |
+
</div>
|
62 |
+
<!-- /support -->
|
63 |
+
|
64 |
+
<!-- Installed modules -->
|
65 |
+
<div class="postbox installed-modules">
|
66 |
+
<h3 class="hndle"><span><?php _ex( 'Installed Modules', 'admin sidebar', 'WPBDM' ); ?></span></h3>
|
67 |
+
<div class="inside">
|
68 |
+
<ul>
|
69 |
+
<?php
|
70 |
+
global $wpbdp;
|
71 |
+
foreach ( $modules as $mod_info ):
|
72 |
+
?>
|
73 |
+
<li class="li_link">
|
74 |
+
<a href="http://businessdirectoryplugin.com/downloads/<?php echo $mod_info[0]; ?>/?ref=wp" target="_blank"><?php echo $mod_info[1]; ?></a>:<br />
|
75 |
+
<?php
|
76 |
+
if ( $wpbdp->has_module( $mod_info[0] ) ):
|
77 |
+
echo _x( 'Installed', 'admin sidebar', 'WPBDM' );
|
78 |
+
else:
|
79 |
+
echo _x( 'Not Installed', 'admin sidebar', 'WPBDM' );
|
80 |
+
endif;
|
81 |
+
?>
|
82 |
+
</li>
|
83 |
+
<?php endforeach; ?>
|
84 |
+
<li class="li_link">
|
85 |
+
<a href="http://businessdirectoryplugin.com/"><?php _ex('Enhanced Categories Module', 'admin sidebar', 'WPBDM'); ?></a>:<br />
|
86 |
+
<?php echo $wpbdp->has_module('categories') ? _x('Installed', 'admin sidebar', 'WPBDM') : _x('Not Installed', 'admin sidebar', 'WPBDM'); ?>
|
87 |
+
</li>
|
88 |
+
</ul>
|
89 |
+
</div>
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
</div>
|
admin/templates/transactions.tpl.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header( _x( 'Transactions', 'admin transactions', 'WPBDM' ), 'admin-transactions' );
|
3 |
+
wpbdp_admin_notices();
|
4 |
+
?>
|
5 |
+
|
6 |
+
<?php $table->views(); ?>
|
7 |
+
<?php $table->display(); ?>
|
8 |
+
|
9 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/templates/uninstall-capture-form.tpl.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$action = isset( $action ) ? $action : '';
|
3 |
+
|
4 |
+
$reasons = array(
|
5 |
+
'1' => _x( 'It doesn\'t work with my theme/plugins/site', 'uninstall', 'WPBDM' ),
|
6 |
+
'2' => _x( 'I can\'t set it up/Too complicated', 'uninstall', 'WPBDM' ),
|
7 |
+
'3' => _x( 'Doesn\'t solve my problem', 'uninstall', 'WPBDM' ),
|
8 |
+
'4' => _x( 'Don\'t need it anymore/Not using it', 'uninstall', 'WPBDM' ),
|
9 |
+
'0' => _x( 'Other', 'uninstall', 'WPBDM' )
|
10 |
+
);
|
11 |
+
?>
|
12 |
+
|
13 |
+
<form id="wpbdp-uninstall-capture-form" action="<?php echo $action; ?>" method="post">
|
14 |
+
<?php wp_nonce_field( 'uninstall bd' ); ?>
|
15 |
+
|
16 |
+
<p><?php _ex( 'We\'re sorry to see you leave. Could you take 10 seconds and answer one question for us to help us make the product better for everyone in the future?',
|
17 |
+
'uninstall',
|
18 |
+
'WPBDM' ); ?></p>
|
19 |
+
<p><b><?php _ex( 'Why are you deleting Business Directory Plugin?', 'uninstall', 'WPBDM' ); ?></b></p>
|
20 |
+
|
21 |
+
<div class="reasons">
|
22 |
+
<?php foreach ( $reasons as $r => $l ): ?>
|
23 |
+
<div class="reason">
|
24 |
+
<label>
|
25 |
+
<input type="radio" name="uninstall[reason_id]" value="<?php echo $r; ?>" /> <?php echo $l; ?>
|
26 |
+
</label>
|
27 |
+
|
28 |
+
<?php if ( 0 == $r ): ?>
|
29 |
+
<br /><textarea name="uninstall[reason_text]" placeholder="<?php _ex( 'Please tell us why are you deleting Business Directory Plugin.', 'uninstall', 'WPBDM' ); ?>"></textarea>
|
30 |
+
<?php endif; ?>
|
31 |
+
</div>
|
32 |
+
<?php endforeach; ?>
|
33 |
+
</div>
|
34 |
+
|
35 |
+
<p class="buttons">
|
36 |
+
<input type="submit" value="<?php _ex( 'Uninstall Plugin', 'uninstall', 'WPBDM'); ?>" class="button button-primary" />
|
37 |
+
</p>
|
38 |
+
</form>
|
admin/templates/uninstall-complete.tpl.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
echo wpbdp_admin_header(_x('Uninstall Business Directory', 'admin uninstall', 'WPBDM'));
|
3 |
+
?>
|
4 |
+
|
5 |
+
<?php wpbdp_admin_notices(); ?>
|
6 |
+
|
7 |
+
<p><?php _ex("Uninstall completed.", 'admin uninstall', "WPBDM"); ?></p>
|
8 |
+
<p><a href="<?php echo admin_url(); ?>"><?php _ex('Return to Dashboard.', 'admin uninstall', 'WPBDM'); ?></p>
|
9 |
+
|
10 |
+
<?php
|
11 |
+
echo wpbdp_admin_footer();
|
12 |
+
?>
|
admin/templates/uninstall-confirm.tpl.php
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php echo wpbdp_admin_header( _x( 'Uninstall Business Directory Plugin', 'uninstall', 'WPBDM' ) ); ?>
|
2 |
+
|
3 |
+
<?php wpbdp_admin_notices(); ?>
|
4 |
+
|
5 |
+
<?php
|
6 |
+
echo wpbdp_render_page( WPBDP_PATH . 'admin/templates/uninstall-capture-form.tpl.php' );
|
7 |
+
?>
|
8 |
+
|
9 |
+
<?php echo wpbdp_admin_footer(); ?>
|
admin/tracking.php
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !defined( 'WPBDP_VERSION' ) ) die; // This page should not be called directly.
|
3 |
+
|
4 |
+
/**
|
5 |
+
* @package admin
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( !class_exists( 'WPBDP_SiteTracking' ) ) {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Class used for anonymously tracking of users setups.
|
12 |
+
* @since 3.2
|
13 |
+
*/
|
14 |
+
class WPBDP_SiteTracking {
|
15 |
+
|
16 |
+
const TRACKING_URL = 'http://data.businessdirectoryplugin.com/tr/';
|
17 |
+
|
18 |
+
public function __construct() {
|
19 |
+
if ( ! wpbdp_get_option( 'tracking-on', false ) )
|
20 |
+
return;
|
21 |
+
|
22 |
+
if ( !wp_next_scheduled( 'wpbdp_site_tracking' ) ) {
|
23 |
+
wp_schedule_event( current_time( 'timestamp' ), 'daily', 'wpbdp_site_tracking' );
|
24 |
+
}
|
25 |
+
|
26 |
+
add_action( 'wpbdp_site_tracking', array( $this, 'tracking' ) );
|
27 |
+
// do_action( 'wpbdp_site_tracking' );
|
28 |
+
}
|
29 |
+
|
30 |
+
public function site_hash() {
|
31 |
+
$hash = get_option( 'wpbdp-site_tracking_hash', '' );
|
32 |
+
|
33 |
+
if ( !$hash ) {
|
34 |
+
$hash = sha1( site_url() );
|
35 |
+
update_option( 'wpbdp-site_tracking_hash', $hash );
|
36 |
+
}
|
37 |
+
|
38 |
+
return $hash;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function tracking() {
|
42 |
+
global $wpdb;
|
43 |
+
|
44 |
+
wpbdp_log( 'Performing (scheduled) site tracking.' );
|
45 |
+
|
46 |
+
$site_hash = $this->site_hash();
|
47 |
+
$data = get_transient( 'wpbdp-site_tracking_data' );
|
48 |
+
|
49 |
+
if ( !$data ) {
|
50 |
+
wpbdp_log( 'Gathering site tracking metrics.' );
|
51 |
+
|
52 |
+
$data = array();
|
53 |
+
|
54 |
+
// General site info.
|
55 |
+
$data['hash'] = $site_hash;
|
56 |
+
$data['site-info'] = array(
|
57 |
+
'title' => get_bloginfo( 'name' ),
|
58 |
+
'wp-version' => get_bloginfo( 'version' ),
|
59 |
+
'bd-version' => WPBDP_VERSION,
|
60 |
+
/*'url' => site_url()*/
|
61 |
+
'lang' => get_locale(),
|
62 |
+
'users' => count( get_users() )
|
63 |
+
);
|
64 |
+
|
65 |
+
// Plugins info.
|
66 |
+
if ( !function_exists( 'get_plugin_data' ) )
|
67 |
+
require_once ABSPATH . 'wp-admin/includes/admin.php';
|
68 |
+
|
69 |
+
$data['plugins'] = array();
|
70 |
+
foreach ( get_option( 'active_plugins' ) as $path ) {
|
71 |
+
$plugin = get_plugin_data( WP_PLUGIN_DIR . '/' . $path );
|
72 |
+
|
73 |
+
$data['plugins'][] = array(
|
74 |
+
'id' => str_replace( '/' . basename( $path ), '', $path ),
|
75 |
+
'name' => wpbdp_getv( $plugin, 'Name', '' ),
|
76 |
+
'version' => wpbdp_getv( $plugin, 'Version', '' ),
|
77 |
+
'plugin_uri' => wpbdp_getv( $plugin, 'PluginURI', '' ),
|
78 |
+
'author' => wpbdp_getv( $plugin, 'AuthorName', '' ),
|
79 |
+
'author_uri' => wpbdp_getv( $plugin, 'AuthorURI', '' )
|
80 |
+
);
|
81 |
+
}
|
82 |
+
|
83 |
+
// Theme info.
|
84 |
+
$data['theme'] = array();
|
85 |
+
|
86 |
+
if ( function_exists( 'wp_get_theme' ) ) {
|
87 |
+
$theme = wp_get_theme();
|
88 |
+
|
89 |
+
foreach ( array( 'Name', 'ThemeURI', 'Version', 'Author', 'AuthorURI' ) as $k ) {
|
90 |
+
$data['theme'][ strtolower( $k ) ] = $theme->display( $k, false, false );
|
91 |
+
}
|
92 |
+
|
93 |
+
$data['theme']['parent'] = array();
|
94 |
+
if ( $theme_parent = $theme->parent() ) {
|
95 |
+
foreach ( array( 'Name', 'ThemeURI', 'Version', 'Author', 'AuthorURI' ) as $k ) {
|
96 |
+
$data['theme']['parent'][ strtolower( $k ) ] = $theme_parent->display( $k, false, false );
|
97 |
+
}
|
98 |
+
} else {
|
99 |
+
$data['theme']['parent'] = null;
|
100 |
+
}
|
101 |
+
} else {
|
102 |
+
$theme = (object) get_theme_data( get_stylesheet_directory() . '/style.css' );
|
103 |
+
|
104 |
+
foreach ( array( 'Name', 'Version', 'Author' ) as $k ) {
|
105 |
+
$data['theme'][ strtolower( $k ) ] = wpbdp_getv( $theme, $k, '' );
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
// Posts.
|
110 |
+
$data['posts'] = array();
|
111 |
+
|
112 |
+
foreach ( get_post_types( array( 'public' => true ) ) as $post_type ) {
|
113 |
+
$count = wp_count_posts( $post_type );
|
114 |
+
$data['posts'][ $post_type ] = intval( $count->publish );
|
115 |
+
}
|
116 |
+
|
117 |
+
// Taxonomies.
|
118 |
+
$data['taxonomies'] = array();
|
119 |
+
|
120 |
+
foreach ( get_taxonomies( array( 'public' => true ), 'objects' ) as $tax ) {
|
121 |
+
$data['taxonomies'][ $tax->name ] = array(
|
122 |
+
'name' => $tax->name,
|
123 |
+
'label' => $tax->label,
|
124 |
+
'terms' => intval( wp_count_terms( $tax->name, array( 'hide_empty' => 0 ) ) )
|
125 |
+
);
|
126 |
+
}
|
127 |
+
|
128 |
+
// Environment.
|
129 |
+
$data['environment'] = array();
|
130 |
+
$data['environment']['os'] = php_uname( 's' ) . ' ' . php_uname( 'r' ) . ' ' . php_uname( 'm' );
|
131 |
+
$data['environment']['php'] = phpversion();
|
132 |
+
$data['environment']['mysql'] = $wpdb->get_var( 'SELECT @@version' );
|
133 |
+
$data['environment']['server-software'] = $_SERVER['SERVER_SOFTWARE'];
|
134 |
+
|
135 |
+
wp_remote_post( self::TRACKING_URL, array(
|
136 |
+
'method' => 'POST',
|
137 |
+
'blocking' => false,
|
138 |
+
'body' => $data
|
139 |
+
) );
|
140 |
+
|
141 |
+
set_transient( 'wpbdp-site_tracking_data', true, 7 * 60 * 60 * 24 );
|
142 |
+
|
143 |
+
}
|
144 |
+
// delete_transient( 'wpbdp-site_tracking_data' );
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @since 3.5.2
|
149 |
+
*/
|
150 |
+
public function track_uninstall( $data = array() ) {
|
151 |
+
$data = is_array( $data ) ? $data : null;
|
152 |
+
$hash = $this->site_hash();
|
153 |
+
|
154 |
+
if ( ! isset( $data['reason_id'] ) )
|
155 |
+
return;
|
156 |
+
|
157 |
+
$reason = $data['reason_id'];
|
158 |
+
$text = isset( $data['reason_text'] ) ? trim( $data['reason_text'] ) : '';
|
159 |
+
|
160 |
+
if ( $reason < 0 || $reason > 4 )
|
161 |
+
return;
|
162 |
+
|
163 |
+
wp_remote_post( self::TRACKING_URL, array(
|
164 |
+
'method' => 'POST',
|
165 |
+
'blocking' => true,
|
166 |
+
'body' => array( 'uninstall' => '1',
|
167 |
+
'hash' => $hash,
|
168 |
+
'reason' => $reason,
|
169 |
+
'text' => $text )
|
170 |
+
) );
|
171 |
+
}
|
172 |
+
|
173 |
+
public static function handle_ajax_response() {
|
174 |
+
if ( !wp_verify_nonce( $_POST['nonce'], 'wpbdp-set_site_tracking' ) )
|
175 |
+
exit();
|
176 |
+
|
177 |
+
if ( isset( $_POST['enable_tracking'] ) ) {
|
178 |
+
update_option( 'wpbdp-show-tracking-pointer', 0 );
|
179 |
+
|
180 |
+
if ( intval( $_POST['enable_tracking'] ) ) {
|
181 |
+
wpbdp_set_option( 'tracking-on', true );
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
public static function request_js() {
|
187 |
+
$content = '';
|
188 |
+
$content .= '<h3>' . _x( 'Help Improve Business Directory', 'tracking', 'WPBDM' ) . '</h3>';
|
189 |
+
$content .= '<p>';
|
190 |
+
$content .= _x( 'Can Business Directory keep track of your theme, plugins, and other non-personal, non-identifying information to help us in testing the plugin for future releases?', 'tracking', 'WPBDM' );
|
191 |
+
$content .= '<br />';
|
192 |
+
$content .= '• ' . sprintf( '<a href="%s" target="_blank">%s</a>', 'http://businessdirectoryplugin.com/what-we-track', _x( 'What do you track?', 'tracking', 'WPBDM' ) );
|
193 |
+
$content .= '</p>';
|
194 |
+
?>
|
195 |
+
<script type="text/javascript">
|
196 |
+
//<![CDATA[
|
197 |
+
jQuery(function($){
|
198 |
+
function WPBDP_SiteTracking_answer(enable) {
|
199 |
+
var args = {
|
200 |
+
action: "wpbdp-set_site_tracking",
|
201 |
+
enable_tracking: enable ? 1 : 0,
|
202 |
+
nonce: "<?php echo wp_create_nonce( 'wpbdp-set_site_tracking' ); ?>"
|
203 |
+
};
|
204 |
+
|
205 |
+
$.post(ajaxurl, args, function() {
|
206 |
+
$('#wp-pointer-0').remove();
|
207 |
+
});
|
208 |
+
}
|
209 |
+
|
210 |
+
$('#wpadminbar').pointer({
|
211 |
+
'content': <?php echo json_encode( $content ); ?>,
|
212 |
+
'position': { 'edge': 'top', 'align': 'center' },
|
213 |
+
'buttons': function(event, t) {
|
214 |
+
var do_not_track = $('<a id="wpbdp-pointer-b2" class="button-secondary" style="margin-right: 5px;"><?php _ex("No, Thanks.", "tracking", "WPBDM") ?></a>');
|
215 |
+
do_not_track.bind('click.pointer', function() { t.element.pointer('close'); });
|
216 |
+
|
217 |
+
return do_not_track;
|
218 |
+
}
|
219 |
+
}).pointer('open');
|
220 |
+
|
221 |
+
$('#wpbdp-pointer-b2').before('<a id="wpbdp-pointer-b1" class="button-primary"><?php _ex("Allow Tracking", "tracking", "WPBDM"); ?></a>');
|
222 |
+
|
223 |
+
$('#wpbdp-pointer-b1').click(function(){
|
224 |
+
WPBDP_SiteTracking_answer( true );
|
225 |
+
});
|
226 |
+
|
227 |
+
$('#wpbdp-pointer-b2').click(function(){
|
228 |
+
WPBDP_SiteTracking_answer( false );
|
229 |
+
});
|
230 |
+
});
|
231 |
+
//]]>
|
232 |
+
</script>
|
233 |
+
<?php
|
234 |
+
}
|
235 |
+
|
236 |
+
}
|
237 |
+
|
238 |
+
}
|
admin/transactions.php
ADDED
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( !class_exists( 'WP_List_Table' ) )
|
3 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
4 |
+
|
5 |
+
class WPBDP_TransactionsTable extends WP_List_Table {
|
6 |
+
|
7 |
+
public function __construct() {
|
8 |
+
parent::__construct(array(
|
9 |
+
'singular' => _x( 'transaction', 'admin transactions', 'WPBDM' ),
|
10 |
+
'plural' => _x( 'transactions', 'admin transactions', 'WPBDM' ),
|
11 |
+
'ajax' => false
|
12 |
+
));
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get_columns() {
|
16 |
+
return array(
|
17 |
+
'id' => _x( 'ID', 'admin transactions', 'WPBDM' ),
|
18 |
+
'payment_type' => _x( 'Type', 'admin transactions', 'WPBDM' ),
|
19 |
+
'listing' => _x( 'Listing', 'admin transactions', 'WPBDM' ),
|
20 |
+
'status' => _x( 'Status', 'admin transactions', 'WPBDM' ),
|
21 |
+
'amount' => _x( 'Amount', 'admin transactions', 'WPBDM' ),
|
22 |
+
'created_on' => _x( 'Date', 'admin transactions', 'WPBDM' ),
|
23 |
+
'actions' => ''
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
protected function column_id( $item ) {
|
28 |
+
return $item->id;
|
29 |
+
}
|
30 |
+
|
31 |
+
protected function column_payment_type( $item ) {
|
32 |
+
$payment_trans = array(
|
33 |
+
'initial' => _x( 'Listing Submit (Initial Payment)', 'admin transactions', 'WPBDM' ),
|
34 |
+
'edit' => _x( 'Listing Edit (Category Fee)', 'admin transactions', 'WPBDM' ),
|
35 |
+
'renewal' => _x( 'Renewal', 'admin transactions', 'WPBDM' ),
|
36 |
+
'upgrade-to-sticky' => _x( 'Upgrade to Featured', 'admin transactions', 'WPBDM' )
|
37 |
+
);
|
38 |
+
|
39 |
+
$html = '';
|
40 |
+
$html .= $payment_trans[ $item->payment_type ];
|
41 |
+
|
42 |
+
$html .= '<div class="more-details" style="display: none;">' . $this->more_details( $item ) . '</div>';
|
43 |
+
|
44 |
+
return $html;
|
45 |
+
}
|
46 |
+
|
47 |
+
private function more_details( $item ) {
|
48 |
+
$item->payerinfo = unserialize( $item->payerinfo );
|
49 |
+
|
50 |
+
$html = '';
|
51 |
+
$html .= '<dl>';
|
52 |
+
|
53 |
+
$html .= '<dt>' . _x( 'Gateway', 'admin transactions', 'WPBDM' ) . '</dt>';
|
54 |
+
$html .= '<dd>'. ( $item->gateway ? $item->gateway : '--' ) . '</dd>';
|
55 |
+
$html .= '<dt>' . _x( 'Payer Info', 'admin transactions', 'WPBDM' ) . '</dt>';
|
56 |
+
$html .= '<dd>';
|
57 |
+
$html .= sprintf( '%s: %s', _x( 'Name', 'admin transactions', 'WPBDM' ), wpbdp_getv( $item->payerinfo, 'name', '--' ) );
|
58 |
+
$html .= '<br />';
|
59 |
+
$html .= sprintf( '%s: %s', _x( 'E-Mail', 'admin transactions', 'WPBDM' ), wpbdp_getv( $item->payerinfo, 'email', '--' ) );
|
60 |
+
$html .= '</dd>';
|
61 |
+
|
62 |
+
if ( $item->processed_on ) {
|
63 |
+
$html .= '<dt>' . _x( 'Processed On', 'admin transactions', 'WPBDM' ) . '</dt>';
|
64 |
+
$html .= '<dd>' . date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format ' ), strtotime( $item->processed_on ) ) . '</dd>';
|
65 |
+
$html .= '<dt>' . _x( 'Processed By', 'admin transactions', 'WPBDM' ) . '</dt>';
|
66 |
+
$html .= '<dd>' . $item->processed_by . '</dd>';
|
67 |
+
}
|
68 |
+
|
69 |
+
$html .= '</dl>';
|
70 |
+
|
71 |
+
return $html;
|
72 |
+
}
|
73 |
+
|
74 |
+
protected function column_listing( $item ) {
|
75 |
+
return sprintf( '<a href="%s">%s</a>',
|
76 |
+
get_permalink( $item->listing_id ),
|
77 |
+
get_the_title( $item->listing_id ) );
|
78 |
+
}
|
79 |
+
|
80 |
+
protected function column_status( $item ) {
|
81 |
+
return sprintf( '<span class="tag %s">%s</span>',
|
82 |
+
$item->status,
|
83 |
+
strtoupper( $item->status ) );
|
84 |
+
}
|
85 |
+
|
86 |
+
protected function column_amount( $item ) {
|
87 |
+
return wpbdp_format_currency( $item->amount );
|
88 |
+
}
|
89 |
+
|
90 |
+
protected function column_created_on( $item ) {
|
91 |
+
return date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
|
92 |
+
strtotime( $item->created_on ) );
|
93 |
+
}
|
94 |
+
|
95 |
+
protected function column_actions( $item ) {
|
96 |
+
$actions = array();
|
97 |
+
|
98 |
+
if ( $item->status == 'pending' ) {
|
99 |
+
$actions['approve_'] = sprintf( '<a href="%s">%s</a>',
|
100 |
+
add_query_arg( array( 'action' => 'approve', 'id' => $item->id ) ),
|
101 |
+
_x( 'Approve', 'admin transactions', 'WPBDM' )
|
102 |
+
);
|
103 |
+
$actions['reject_'] = sprintf( '<a href="%s">%s</a>',
|
104 |
+
add_query_arg( array( 'action' => 'reject', 'id' => $item->id ) ),
|
105 |
+
_x( 'Reject', 'admin transactions', 'WPBDM' )
|
106 |
+
);
|
107 |
+
}
|
108 |
+
|
109 |
+
if ( $item->status != 'pending' )
|
110 |
+
$actions['details'] = sprintf( '<a href="#" class="details-link">%s</a>',
|
111 |
+
_x( '+ Details', 'admin transactions', 'WPBDM' )
|
112 |
+
);
|
113 |
+
|
114 |
+
$actions['delete'] = sprintf( '<a href="%s" class="delete">%s</a>',
|
115 |
+
add_query_arg( array( 'action' => 'delete', 'id' => $item->id ) ),
|
116 |
+
_x( 'Delete', 'admin transactions', 'WPBDM' )
|
117 |
+
);
|
118 |
+
|
119 |
+
return implode( ' | ', $actions );
|
120 |
+
/* if ( $item->processed_on ) {
|
121 |
+
return date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
|
122 |
+
strtotime( $item->processed_on ) );
|
123 |
+
}
|
124 |
+
|
125 |
+
return '—';*/
|
126 |
+
}
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
public function get_views() {
|
131 |
+
global $wpdb;
|
132 |
+
|
133 |
+
$views = array();
|
134 |
+
|
135 |
+
// filter by status
|
136 |
+
$count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments" );
|
137 |
+
$views['all'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
138 |
+
add_query_arg( 'status', 'all' ),
|
139 |
+
wpbdp_getv( $_REQUEST, 'status' ) == 'all' ? 'current' : '',
|
140 |
+
_x( 'All', 'admin transactions', 'WPBDM' ) ,
|
141 |
+
number_format_i18n( $count )
|
142 |
+
);
|
143 |
+
|
144 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments WHERE status = %s", 'approved' ) );
|
145 |
+
$views['approved'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
146 |
+
add_query_arg( 'status', 'approved' ),
|
147 |
+
wpbdp_getv( $_REQUEST, 'status' ) == 'approved' ? 'current' : '',
|
148 |
+
_x( 'Approved', 'admin transactions', 'WPBDM' ) ,
|
149 |
+
number_format_i18n( $count )
|
150 |
+
);
|
151 |
+
|
152 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments WHERE status = %s", 'pending' ) );
|
153 |
+
$views['pending'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
154 |
+
add_query_arg( 'status', 'pending' ),
|
155 |
+
wpbdp_getv( $_REQUEST, 'status', 'pending' ) == 'pending' ? 'current' : '',
|
156 |
+
_x( 'Pending', 'admin transactions', 'WPBDM' ) ,
|
157 |
+
number_format_i18n( $count )
|
158 |
+
);
|
159 |
+
|
160 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments WHERE status = %s", 'rejected' ) );
|
161 |
+
$views['rejected'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
162 |
+
add_query_arg( 'status', 'rejected' ),
|
163 |
+
wpbdp_getv( $_REQUEST, 'status' ) == 'rejected' ? 'current' : '',
|
164 |
+
_x( 'Rejected', 'admin transactions', 'WPBDM' ) ,
|
165 |
+
number_format_i18n( $count )
|
166 |
+
);
|
167 |
+
|
168 |
+
// by type
|
169 |
+
/*$views['initial'] = sprintf( '<a href="%s" class="%s">%s <span class="count">(%s)</span></a>',
|
170 |
+
add_query_arg( 'filter', 'rejected' ),
|
171 |
+
wpbdp_getv( $_REQUEST, 'filter' ) == 'rejected' ? 'current' : '',
|
172 |
+
_x( 'Rejected', 'admin transactions', 'WPBDM' ) ,
|
173 |
+
number_format_i18n( $count )
|
174 |
+
); */
|
175 |
+
|
176 |
+
return $views;
|
177 |
+
}
|
178 |
+
|
179 |
+
public function prepare_items() {
|
180 |
+
global $wpdb;
|
181 |
+
|
182 |
+
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
|
183 |
+
|
184 |
+
$where = '';
|
185 |
+
$current_filter = wpbdp_getv( $_GET, 'status', 'pending' );
|
186 |
+
if ( $current_filter != 'all' )
|
187 |
+
$where .= $wpdb->prepare( "AND status = %s", $current_filter );
|
188 |
+
|
189 |
+
$query = "SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE 1=1 {$where} ORDER BY created_on DESC";
|
190 |
+
$this->items = $wpdb->get_results( $query );
|
191 |
+
}
|
192 |
+
|
193 |
+
}
|
194 |
+
|
195 |
+
class WPBDP_TransactionsAdmin {
|
196 |
+
|
197 |
+
private function transactions_table() {
|
198 |
+
$table = new WPBDP_TransactionsTable();
|
199 |
+
$table->prepare_items();
|
200 |
+
|
201 |
+
wpbdp_render_page( WPBDP_PATH . 'admin/templates/transactions.tpl.php',
|
202 |
+
array( 'table' => $table ),
|
203 |
+
true );
|
204 |
+
}
|
205 |
+
|
206 |
+
private function clear_transactions() {
|
207 |
+
global $wpdb;
|
208 |
+
|
209 |
+
// TODO: delete transactions for posts that do not exist
|
210 |
+
|
211 |
+
|
212 |
+
// delete unnecessary renewals
|
213 |
+
$renewals = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}wpbdp_payments WHERE payment_type = %s AND status = %s",
|
214 |
+
'renewal',
|
215 |
+
'pending' ) );
|
216 |
+
foreach ( $renewals as $tid ) {
|
217 |
+
$trans = wpbdp_payments_api()->get_transaction( $tid );
|
218 |
+
if ( !is_array( $trans->extra_data ) ) {
|
219 |
+
$trans->extra_data = unserialize( $trans->extra_data );
|
220 |
+
}
|
221 |
+
|
222 |
+
if ( intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", $trans->extra_data['renewal_id'] ) ) ) == 0 ) {
|
223 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments WHERE id = %d", $tid ) );
|
224 |
+
}
|
225 |
+
}
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
public function dispatch() {
|
230 |
+
global $wpdb;
|
231 |
+
|
232 |
+
$api = wpbdp_payments_api();
|
233 |
+
|
234 |
+
switch ( wpbdp_getv( $_REQUEST, 'action' ) ) {
|
235 |
+
case 'approve':
|
236 |
+
if ( $trans = $api->get_transaction( $_GET['id'] ) ) {
|
237 |
+
$trans->processed_on = current_time( 'mysql' );
|
238 |
+
$trans->processed_by = 'admin';
|
239 |
+
$trans->status = 'approved';
|
240 |
+
$api->save_transaction( $trans );
|
241 |
+
}
|
242 |
+
|
243 |
+
wpbdp_admin()->messages[] = _x( 'The transaction has been approved.', 'admin', 'WPBDM' );
|
244 |
+
break;
|
245 |
+
|
246 |
+
case 'reject':
|
247 |
+
if ( $trans = $api->get_transaction( $_GET['id'] ) ) {
|
248 |
+
$trans->processed_on = current_time( 'mysql' );
|
249 |
+
$trans->processed_by = 'admin';
|
250 |
+
$trans->status = 'rejected';
|
251 |
+
$api->save_transaction( $trans );
|
252 |
+
}
|
253 |
+
|
254 |
+
wpbdp_admin()->messages[] = _x( 'The transaction has been rejected.', 'admin', 'WPBDM' );
|
255 |
+
break;
|
256 |
+
|
257 |
+
case 'delete':
|
258 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments WHERE id = %d", $_GET['id'] ) );
|
259 |
+
wpbdp_admin()->messages[] = _x( 'The transaction has been deleted.', 'admin', 'WPBDM' );
|
260 |
+
|
261 |
+
break;
|
262 |
+
|
263 |
+
default:
|
264 |
+
break;
|
265 |
+
}
|
266 |
+
|
267 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'action', 'id' ), $_SERVER['REQUEST_URI'] );
|
268 |
+
|
269 |
+
$this->clear_transactions();
|
270 |
+
$this->transactions_table();
|
271 |
+
}
|
272 |
+
|
273 |
+
public static function admin_menu_cb() {
|
274 |
+
$instance = new WPBDP_TransactionsAdmin();
|
275 |
+
$instance->dispatch();
|
276 |
+
}
|
277 |
+
|
278 |
+
}
|
business-directory-plugin.php
ADDED
@@ -0,0 +1,1578 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Plugin Name: Business Directory Plugin
|
4 |
+
* Plugin URI: http://www.businessdirectoryplugin.com
|
5 |
+
* Description: Provides the ability to maintain a free or paid business directory on your WordPress powered site.
|
6 |
+
* Version: 3.5.4
|
7 |
+
* Author: D. Rodenbaugh
|
8 |
+
* Author URI: http://businessdirectoryplugin.com
|
9 |
+
* License: GPLv2 or any later version
|
10 |
+
*/
|
11 |
+
|
12 |
+
/* Copyright 2009-2015, Skyline Consulting and D. Rodenbaugh
|
13 |
+
|
14 |
+
This program is free software; you can redistribute it and/or modify
|
15 |
+
it under the terms of the GNU General Public License, version 2 or later, as
|
16 |
+
published by the Free Software Foundation.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
reCAPTCHA used with permission of Mike Crawford & Ben Maurer, http://recaptcha.net
|
27 |
+
*/
|
28 |
+
|
29 |
+
// Do not allow direct loading of this file.
|
30 |
+
if( preg_match( '#' . basename( __FILE__ ) . '#', $_SERVER['PHP_SELF'] ) )
|
31 |
+
exit();
|
32 |
+
|
33 |
+
define( 'WPBDP_VERSION', '3.5.4' );
|
34 |
+
|
35 |
+
define( 'WPBDP_PATH', plugin_dir_path( __FILE__ ) );
|
36 |
+
define( 'WPBDP_URL', trailingslashit( plugins_url( '/', __FILE__ ) ) );
|
37 |
+
define( 'WPBDP_TEMPLATES_PATH', WPBDP_PATH . 'templates' );
|
38 |
+
|
39 |
+
define( 'WPBDP_POST_TYPE', 'wpbdp_listing' );
|
40 |
+
define( 'WPBDP_CATEGORY_TAX', 'wpbdp_category' );
|
41 |
+
define( 'WPBDP_TAGS_TAX', 'wpbdp_tag' );
|
42 |
+
|
43 |
+
require_once( WPBDP_PATH . 'core/api.php' );
|
44 |
+
require_once( WPBDP_PATH . 'core/compatibility/class-compat.php' );
|
45 |
+
require_once( WPBDP_PATH . 'core/utils.php' );
|
46 |
+
require_once( WPBDP_PATH . 'admin/tracking.php' );
|
47 |
+
require_once( WPBDP_PATH . 'admin/class-admin.php' );
|
48 |
+
require_once( WPBDP_PATH . 'core/class-settings.php' );
|
49 |
+
require_once( WPBDP_PATH . 'core/form-fields.php' );
|
50 |
+
require_once( WPBDP_PATH . 'core/payment.php' );
|
51 |
+
include_once( WPBDP_PATH . 'core/gateways-googlewallet.php' );
|
52 |
+
require_once( WPBDP_PATH . 'core/listings.php' );
|
53 |
+
require_once( WPBDP_PATH . 'core/templates-generic.php' );
|
54 |
+
require_once( WPBDP_PATH . 'core/templates-listings.php' );
|
55 |
+
require_once( WPBDP_PATH . 'core/templates-ui.php' );
|
56 |
+
require_once( WPBDP_PATH . 'core/installer.php' );
|
57 |
+
require_once( WPBDP_PATH . 'core/views.php' );
|
58 |
+
require_once( WPBDP_PATH . 'core/licensing.php' );
|
59 |
+
require_once( WPBDP_PATH . 'core/seo.php' );
|
60 |
+
|
61 |
+
|
62 |
+
global $wpbdp;
|
63 |
+
|
64 |
+
|
65 |
+
/**
|
66 |
+
* The main plugin class.
|
67 |
+
*/
|
68 |
+
class WPBDP_Plugin {
|
69 |
+
|
70 |
+
public function __construct() {
|
71 |
+
register_activation_hook( __FILE__, array( &$this, 'plugin_activation' ) );
|
72 |
+
register_deactivation_hook( __FILE__, array( &$this, 'plugin_deactivation' ) );
|
73 |
+
|
74 |
+
// Enable debugging if needed.
|
75 |
+
if ( defined( 'WPBDP_DEBUG' ) && true == WPBDP_DEBUG )
|
76 |
+
$this->debug_on();
|
77 |
+
|
78 |
+
// Load dummy objects in case plugins try to do something at an early stage.
|
79 |
+
$noop = new WPBDP_NoopObject();
|
80 |
+
$this->settings = $noop;
|
81 |
+
$this->controller = $noop;
|
82 |
+
$this->formfields = $noop;
|
83 |
+
$this->admin = $noop;
|
84 |
+
$this->fees = $noop;
|
85 |
+
$this->payments = $noop;
|
86 |
+
$this->listings = $noop;
|
87 |
+
|
88 |
+
$this->licensing = new WPBDP_Licensing();
|
89 |
+
|
90 |
+
add_action( 'plugins_loaded', array( &$this, 'load_i18n' ) );
|
91 |
+
add_action( 'init', array( &$this, 'init' ) );
|
92 |
+
add_action( 'widgets_init', array( &$this, '_register_widgets' ) );
|
93 |
+
|
94 |
+
// For testing the expiration routine only.
|
95 |
+
//add_action('init', create_function('', 'do_action("wpbdp_listings_expiration_check");'), 20);
|
96 |
+
}
|
97 |
+
|
98 |
+
function load_i18n() {
|
99 |
+
$plugin_dir = basename( dirname( __FILE__ ) );
|
100 |
+
$languages_dir = trailingslashit( $plugin_dir . '/languages' );
|
101 |
+
load_plugin_textdomain( 'WPBDM', false, $languages_dir );
|
102 |
+
}
|
103 |
+
|
104 |
+
function init() {
|
105 |
+
$this->compat = new WPBDP_Compat();
|
106 |
+
|
107 |
+
// Register cache groups.
|
108 |
+
wp_cache_add_non_persistent_groups( array( 'wpbdp pages', 'wpbdp formfields', 'wpbdp submit state', 'wpbdp' ) );
|
109 |
+
|
110 |
+
// Register some basic JS resources.
|
111 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_common_scripts' ) );
|
112 |
+
add_action( 'admin_enqueue_scripts', array( &$this, 'register_common_scripts' ) );
|
113 |
+
|
114 |
+
// Initialize settings API.
|
115 |
+
$this->settings = new WPBDP_Settings();
|
116 |
+
$this->formfields = WPBDP_FormFields::instance();
|
117 |
+
|
118 |
+
// Install plugin.
|
119 |
+
$this->settings->register_settings();
|
120 |
+
$this->_register_post_type();
|
121 |
+
$this->install_or_update_plugin();
|
122 |
+
|
123 |
+
if ( $manual_upgrade = get_option( 'wpbdp-manual-upgrade-pending', false ) ) {
|
124 |
+
$installer = new WPBDP_Installer();
|
125 |
+
$installer->setup_manual_upgrade();
|
126 |
+
return;
|
127 |
+
}
|
128 |
+
|
129 |
+
// Display "Settings" link on Plugins page.
|
130 |
+
$plugin_filename = plugin_basename( __FILE__ );
|
131 |
+
add_filter( 'plugin_action_links_' . $plugin_filename, array( &$this, 'plugin_action_links' ) );
|
132 |
+
|
133 |
+
// Initialize APIs.
|
134 |
+
$this->admin = is_admin() ? new WPBDP_Admin() : null;
|
135 |
+
$this->controller = new WPBDP_DirectoryController();
|
136 |
+
$this->fees = new WPBDP_FeesAPI();
|
137 |
+
$this->payments = new WPBDP_PaymentsAPI();
|
138 |
+
$this->listings = new WPBDP_Listings_API();
|
139 |
+
|
140 |
+
$this->_register_image_sizes();
|
141 |
+
$this->handle_recaptcha();
|
142 |
+
|
143 |
+
add_filter('posts_request', create_function('$x', 'wpbdp_debug($x); return $x;')); // used for debugging
|
144 |
+
add_filter('rewrite_rules_array', array( &$this, '_rewrite_rules'));
|
145 |
+
add_filter('query_vars', array( &$this, '_query_vars'));
|
146 |
+
add_filter( 'redirect_canonical', array( &$this, '_redirect_canonical' ), 10, 2 );
|
147 |
+
add_action('template_redirect', array( &$this, '_template_redirect'));
|
148 |
+
add_action('wp_loaded', array( &$this, '_wp_loaded'));
|
149 |
+
|
150 |
+
add_action('pre_get_posts', array( &$this, '_pre_get_posts'));
|
151 |
+
add_action('posts_fields', array( &$this, '_posts_fields'), 10, 2);
|
152 |
+
add_action('posts_orderby', array( &$this, '_posts_orderby'), 10, 2);
|
153 |
+
|
154 |
+
add_filter('comments_template', array( &$this, '_comments_template'));
|
155 |
+
add_filter('taxonomy_template', array( &$this, '_category_template'));
|
156 |
+
add_filter('single_template', array( &$this, '_single_template'));
|
157 |
+
|
158 |
+
add_action( 'wp', array( &$this, '_meta_setup' ) );
|
159 |
+
add_action( 'wp', array( &$this, '_jetpack_compat' ), 11, 1 );
|
160 |
+
add_action( 'wp_head', array( &$this, '_handle_broken_plugin_filters' ), 0 );
|
161 |
+
|
162 |
+
add_filter( 'wp_title', array( &$this, '_meta_title' ), 10, 3 );
|
163 |
+
|
164 |
+
add_action( 'wp_head', array( &$this, '_rss_feed' ) );
|
165 |
+
|
166 |
+
// Register shortcodes.
|
167 |
+
$shortcodes = $this->get_shortcodes();
|
168 |
+
|
169 |
+
foreach ( $shortcodes as $shortcode => &$handler )
|
170 |
+
add_shortcode( $shortcode, $handler );
|
171 |
+
|
172 |
+
do_action( 'wpbdp_loaded' );
|
173 |
+
|
174 |
+
// Expiration hook.
|
175 |
+
add_action( 'wpbdp_listings_expiration_check', array( &$this, '_notify_expiring_listings' ), 0 );
|
176 |
+
|
177 |
+
// Scripts & styles.
|
178 |
+
add_action('wp_enqueue_scripts', array($this, '_enqueue_scripts'));
|
179 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_css_override' ), 30, 0 );
|
180 |
+
|
181 |
+
// Plugin modules initialization.
|
182 |
+
$this->_init_modules();
|
183 |
+
|
184 |
+
// AJAX actions.
|
185 |
+
add_action( 'wp_ajax_wpbdp-file-field-upload', array( &$this, 'ajax_file_field_upload' ) );
|
186 |
+
add_action( 'wp_ajax_nopriv_wpbdp-file-field-upload', array( &$this, 'ajax_file_field_upload' ) );
|
187 |
+
add_action( 'wp_ajax_wpbdp-listing-submit-image-upload', array( &$this, 'ajax_listing_submit_image_upload' ) );
|
188 |
+
add_action( 'wp_ajax_nopriv_wpbdp-listing-submit-image-upload', array( &$this, 'ajax_listing_submit_image_upload' ) );
|
189 |
+
add_action( 'wp_ajax_wpbdp-listing-submit-image-delete', array( &$this, 'ajax_listing_submit_image_delete' ) );
|
190 |
+
add_action( 'wp_ajax_nopriv_wpbdp-listing-submit-image-delete', array( &$this, 'ajax_listing_submit_image_delete' ) );
|
191 |
+
|
192 |
+
// Core sorting options.
|
193 |
+
add_filter( 'wpbdp_listing_sort_options', array( &$this, 'sortbar_sort_options' ) );
|
194 |
+
add_filter( 'wpbdp_query_fields', array( &$this, 'sortbar_query_fields' ) );
|
195 |
+
add_filter( 'wpbdp_query_orderby', array( &$this, 'sortbar_orderby' ) );
|
196 |
+
}
|
197 |
+
|
198 |
+
// {{{ Premium modules.
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Return information about known premium modules.
|
202 |
+
* @return array An array in the form $module_id => $module_information where $module_information contains the keys
|
203 |
+
* 'installed' (True or False),
|
204 |
+
* 'version' (if installed, NULL otherwise),
|
205 |
+
* 'required' (required module version as known to current core version).
|
206 |
+
* @since 3.4
|
207 |
+
*/
|
208 |
+
public function get_premium_modules_data() {
|
209 |
+
static $modules = array(
|
210 |
+
'2checkout' => array( 'WPBDP_2Checkout_Module', '3.4' ),
|
211 |
+
'attachments' => array( 'WPBDP_ListingAttachmentsModule', '3.4' ),
|
212 |
+
'categories' => array( 'WPBDP_CategoriesModule', '3.4' ),
|
213 |
+
'featured-levels' => array( 'WPBDP_FeaturedLevelsModule', '3.4' ),
|
214 |
+
'googlemaps' => array( 'BusinessDirectory_GoogleMapsPlugin', '3.4' ),
|
215 |
+
'payfast' => array( 'WPBDP_Gateways_PayFast', '3.4' ),
|
216 |
+
'paypal' => array( 'WPBDP_PayPal_Module', '3.4' ),
|
217 |
+
'ratings' => array( 'BusinessDirectory_RatingsModule', '3.4' ),
|
218 |
+
'regions' => array( 'WPBDP_RegionsPlugin', '3.4' ),
|
219 |
+
'stripe' => array( 'WPBDP_Stripe_Module', '1.0' ),
|
220 |
+
'zipcodesearch' => array( 'WPBDP_ZIPCodeSearchModule', '3.4' )
|
221 |
+
);
|
222 |
+
|
223 |
+
static $data = null;
|
224 |
+
|
225 |
+
if ( null !== $data )
|
226 |
+
return $data;
|
227 |
+
|
228 |
+
$data = array();
|
229 |
+
|
230 |
+
foreach ( $modules as $module_id => $module_ ) {
|
231 |
+
$module_class = $module_[0];
|
232 |
+
$data[ $module_id ] = array( 'installed' => false,
|
233 |
+
'version' => null,
|
234 |
+
'required' => $module_[1] );
|
235 |
+
|
236 |
+
if ( class_exists( $module_class ) ) {
|
237 |
+
$data[ $module_id ]['installed'] = true;
|
238 |
+
|
239 |
+
if ( defined( $module_class . '::VERSION' ) ) {
|
240 |
+
$data[ $module_id ]['version'] = constant( $module_class . '::VERSION' );
|
241 |
+
}
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
return $data;
|
246 |
+
}
|
247 |
+
|
248 |
+
// }}}
|
249 |
+
|
250 |
+
public function _pre_get_posts(&$query) {
|
251 |
+
global $wpdb;
|
252 |
+
|
253 |
+
if (!$query->is_admin && $query->is_archive && $query->get(WPBDP_CATEGORY_TAX)) {
|
254 |
+
// category page query
|
255 |
+
$query->set('post_status', 'publish');
|
256 |
+
$query->set('post_type', WPBDP_POST_TYPE);
|
257 |
+
$query->set('posts_per_page', wpbdp_get_option( 'listings-per-page' ) > 0 ? wpbdp_get_option( 'listings-per-page' ) : -1);
|
258 |
+
$query->set('orderby', wpbdp_get_option('listings-order-by', 'date'));
|
259 |
+
$query->set('order', wpbdp_get_option('listings-sort', 'ASC'));
|
260 |
+
}
|
261 |
+
}
|
262 |
+
|
263 |
+
public function _posts_fields($fields, $query) {
|
264 |
+
global $wpdb;
|
265 |
+
|
266 |
+
if (!is_admin() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == WPBDP_POST_TYPE) {
|
267 |
+
$is_sticky_query = $wpdb->prepare("(SELECT 1 FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID AND {$wpdb->postmeta}.meta_key = %s AND {$wpdb->postmeta}.meta_value = %s LIMIT 1 ) AS wpbdp_is_sticky",
|
268 |
+
'_wpbdp[sticky]', 'sticky');
|
269 |
+
|
270 |
+
if ( 'paid' == wpbdp_get_option( 'listings-order-by' ) ) {
|
271 |
+
$is_paid_query = "(SELECT 1 FROM {$wpdb->prefix}wpbdp_payments pp WHERE pp.listing_id = {$wpdb->posts}.ID AND pp.amount > 0 LIMIT 1 ) AS wpbdp_is_paid";
|
272 |
+
$fields = $fields . ', ' . $is_sticky_query . ', ' . $is_paid_query;
|
273 |
+
} else {
|
274 |
+
$fields = $fields . ', ' . $is_sticky_query;
|
275 |
+
}
|
276 |
+
|
277 |
+
$fields = apply_filters('wpbdp_query_fields', $fields);
|
278 |
+
}
|
279 |
+
|
280 |
+
return $fields;
|
281 |
+
}
|
282 |
+
|
283 |
+
public function _posts_orderby($orderby, $query) {
|
284 |
+
if (!is_admin() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == WPBDP_POST_TYPE) {
|
285 |
+
$wpbdp_orderby = apply_filters('wpbdp_query_orderby', '');
|
286 |
+
|
287 |
+
if ( 'paid' == wpbdp_get_option( 'listings-order-by' ) ) {
|
288 |
+
$orderby = 'wpbdp_is_sticky DESC, wpbdp_is_paid DESC' . $wpbdp_orderby . ', ' . $orderby;
|
289 |
+
} else {
|
290 |
+
$orderby = 'wpbdp_is_sticky DESC' . $wpbdp_orderby . ', ' . $orderby;
|
291 |
+
}
|
292 |
+
|
293 |
+
}
|
294 |
+
|
295 |
+
return $orderby;
|
296 |
+
}
|
297 |
+
|
298 |
+
private function get_rewrite_rules() {
|
299 |
+
global $wpdb;
|
300 |
+
global $wp_rewrite;
|
301 |
+
|
302 |
+
$rules = array();
|
303 |
+
|
304 |
+
if ( $page_ids = wpbdp_get_page_id( 'main', false ) ) {
|
305 |
+
foreach ( $page_ids as $page_id ) {
|
306 |
+
$page_link = _get_page_link( $page_id );
|
307 |
+
$rewrite_base = str_replace('index.php/', '', rtrim(str_replace(home_url() . '/', '', $page_link), '/'));
|
308 |
+
|
309 |
+
$rules['(' . $rewrite_base . ')/' . $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $page_id . '&paged=$matches[2]';
|
310 |
+
$rules['(' . $rewrite_base . ')/' . wpbdp_get_option('permalinks-category-slug') . '/(.+?)/' . $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $page_id . '&category=$matches[2]&paged=$matches[3]';
|
311 |
+
$rules['(' . $rewrite_base . ')/' . wpbdp_get_option('permalinks-category-slug') . '/(.+?)/?$'] = 'index.php?page_id=' . $page_id . '&category=$matches[2]';
|
312 |
+
$rules['(' . $rewrite_base . ')/' . wpbdp_get_option('permalinks-tags-slug') . '/(.+?)/' . $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $page_id . '&tag=$matches[2]&paged=$matches[3]';
|
313 |
+
$rules['(' . $rewrite_base . ')/' . wpbdp_get_option('permalinks-tags-slug') . '/(.+?)$'] = 'index.php?page_id=' . $page_id . '&tag=$matches[2]';
|
314 |
+
|
315 |
+
if ( wpbdp_get_option( 'permalinks-no-id' ) ) {
|
316 |
+
//$rules['(' . $rewrite_base . ')/([0-9]{1,})/?$'] = 'index.php?page_id=' . $page_id . '&id=$matches[2]';
|
317 |
+
$rules['(' . $rewrite_base . ')/(.*)/?$'] = 'index.php?page_id=' . $page_id . '&listing=$matches[2]';
|
318 |
+
} else {
|
319 |
+
$rules['(' . $rewrite_base . ')/([0-9]{1,})/?(.*)/?$'] = 'index.php?page_id=' . $page_id . '&id=$matches[2]';
|
320 |
+
}
|
321 |
+
}
|
322 |
+
}
|
323 |
+
|
324 |
+
return apply_filters( 'wpbdp_rewrite_rules', $rules );
|
325 |
+
}
|
326 |
+
|
327 |
+
public function _rewrite_rules($rules) {
|
328 |
+
$newrules = $this->get_rewrite_rules();
|
329 |
+
return $newrules + $rules;
|
330 |
+
}
|
331 |
+
|
332 |
+
public function _wp_loaded() {
|
333 |
+
if ($rules = get_option( 'rewrite_rules' )) {
|
334 |
+
foreach ($this->get_rewrite_rules() as $k => $v) {
|
335 |
+
if (!isset($rules[$k]) || $rules[$k] != $v) {
|
336 |
+
global $wp_rewrite;
|
337 |
+
$wp_rewrite->flush_rules();
|
338 |
+
return;
|
339 |
+
}
|
340 |
+
}
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
public function _query_vars($vars) {
|
345 |
+
array_push($vars, 'id');
|
346 |
+
array_push($vars, 'listing');
|
347 |
+
array_push($vars, 'category_id'); // TODO: are we really using this var?
|
348 |
+
array_push($vars, 'category');
|
349 |
+
array_push($vars, 'action'); // TODO: are we really using this var?
|
350 |
+
array_push( $vars, 'wpbdpx' );
|
351 |
+
array_push( $vars, 'region' );
|
352 |
+
|
353 |
+
return $vars;
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Workaround for issue WP bug #16373.
|
358 |
+
* See http://wordpress.stackexchange.com/questions/51530/rewrite-rules-problem-when-rule-includes-homepage-slug.
|
359 |
+
*/
|
360 |
+
public function _redirect_canonical( $redirect_url, $requested_url ) {
|
361 |
+
global $wp_query;
|
362 |
+
|
363 |
+
if ( $main_page_id = wpbdp_get_page_id( 'main' ) ) {
|
364 |
+
if ( is_page() && !is_feed() && isset( $wp_query->queried_object ) &&
|
365 |
+
get_option( 'show_on_front' ) == 'page' &&
|
366 |
+
get_option( 'page_on_front' ) == $wp_query->queried_object->ID ) {
|
367 |
+
return $requested_url;
|
368 |
+
}
|
369 |
+
}
|
370 |
+
|
371 |
+
return $redirect_url;
|
372 |
+
}
|
373 |
+
|
374 |
+
public function _template_redirect() {
|
375 |
+
global $wp_query;
|
376 |
+
|
377 |
+
if ( $wp_query->get( 'wpbdpx' ) ) {
|
378 |
+
// Handle some special wpbdpx actions.
|
379 |
+
$wpbdpx = $wp_query->get( 'wpbdpx' );
|
380 |
+
|
381 |
+
if ( isset( $this->{$wpbdpx} ) && method_exists( $this->{$wpbdpx}, 'process_request' ) ) {
|
382 |
+
$this->{$wpbdpx}->process_request();
|
383 |
+
exit();
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
if ( is_feed() )
|
388 |
+
return;
|
389 |
+
|
390 |
+
// handle some deprecated stuff
|
391 |
+
if ( is_search() && isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] == WPBDP_POST_TYPE ) {
|
392 |
+
$url = add_query_arg( array( 'action' => 'search',
|
393 |
+
'dosrch' => 1,
|
394 |
+
'q' => wpbdp_getv( $_REQUEST, 's', '' ) ), wpbdp_get_page_link( 'main' ) );
|
395 |
+
wp_redirect( $url ); exit;
|
396 |
+
}
|
397 |
+
|
398 |
+
if ( (get_query_var('taxonomy') == WPBDP_CATEGORY_TAX) && (_wpbdp_template_mode('category') == 'page') ) {
|
399 |
+
wp_redirect( add_query_arg('category', get_query_var('term'), wpbdp_get_page_link('main')) ); // XXX
|
400 |
+
exit;
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( (get_query_var('taxonomy') == WPBDP_TAGS_TAX) && (_wpbdp_template_mode('category') == 'page') ) {
|
404 |
+
wp_redirect( add_query_arg('tag', get_query_var('term'), wpbdp_get_page_link('main')) ); // XXX
|
405 |
+
exit;
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( is_single() && (get_query_var('post_type') == WPBDP_POST_TYPE) && (_wpbdp_template_mode('single') == 'page') ) {
|
409 |
+
$url = wpbdp_get_page_link( 'main' );
|
410 |
+
|
411 |
+
if (get_query_var('name')) {
|
412 |
+
wp_redirect( add_query_arg('listing', get_query_var('name'), $url) ); // XXX
|
413 |
+
} else {
|
414 |
+
wp_redirect( add_query_arg('id', get_query_var('p'), $url) ); // XXX
|
415 |
+
}
|
416 |
+
|
417 |
+
exit;
|
418 |
+
}
|
419 |
+
|
420 |
+
global $post;
|
421 |
+
if ( $post && ($post->ID == wpbdp_get_page_id('main')) && (get_query_var('id') || get_query_var('listing')) ) {
|
422 |
+
$id_or_slug = false;
|
423 |
+
|
424 |
+
foreach ( array( 'id', 'preview_id', 'listing' ) as $x ) {
|
425 |
+
if ( get_query_var( $x ) ) {
|
426 |
+
$id_or_slug = get_query_var( $x );
|
427 |
+
break;
|
428 |
+
}
|
429 |
+
}
|
430 |
+
|
431 |
+
$listing = wpbdp_get_post_by_id_or_slug( $id_or_slug, wpbdp_get_option( 'permalinks-no-id' ) ? 'slug' : 'id' );
|
432 |
+
|
433 |
+
if ( ! $listing || ( 'publish' != $listing->post_status && ! current_user_can( 'edit_posts' ) ) ) {
|
434 |
+
$this->controller->action = null;
|
435 |
+
status_header(404);
|
436 |
+
nocache_headers();
|
437 |
+
include( get_404_template() );
|
438 |
+
exit();
|
439 |
+
}
|
440 |
+
}
|
441 |
+
|
442 |
+
}
|
443 |
+
|
444 |
+
public function plugin_activation() {
|
445 |
+
add_action('init', array($this, 'flush_rules'), 11);
|
446 |
+
}
|
447 |
+
|
448 |
+
public function plugin_deactivation() {
|
449 |
+
wp_clear_scheduled_hook('wpbdp_listings_expiration_check');
|
450 |
+
}
|
451 |
+
|
452 |
+
public function flush_rules() {
|
453 |
+
if (function_exists('flush_rewrite_rules'))
|
454 |
+
flush_rewrite_rules(false);
|
455 |
+
}
|
456 |
+
|
457 |
+
// TODO: better validation.
|
458 |
+
public function ajax_listing_submit_image_upload() {
|
459 |
+
$res = new WPBDP_Ajax_Response();
|
460 |
+
|
461 |
+
$listing_id = 0;
|
462 |
+
$state_id = 0;
|
463 |
+
$state = null;
|
464 |
+
|
465 |
+
if ( isset( $_REQUEST['state_id'] ) ) {
|
466 |
+
require_once( WPBDP_PATH . 'core/view-submit-listing.php' );
|
467 |
+
|
468 |
+
$state_id = trim( $_REQUEST['state_id'] );
|
469 |
+
$state = WPBDP_Listing_Submit_State::get( $state_id );
|
470 |
+
|
471 |
+
if ( ! $state )
|
472 |
+
$res->send_error();
|
473 |
+
} else {
|
474 |
+
$listing_id = intval( $_REQUEST['listing_id'] );
|
475 |
+
|
476 |
+
if ( ! $listing_id )
|
477 |
+
$res->send_error();
|
478 |
+
}
|
479 |
+
|
480 |
+
$content_range = null;
|
481 |
+
$size = null;
|
482 |
+
|
483 |
+
if ( isset( $_SERVER['HTTP_CONTENT_RANGE'] ) ) {
|
484 |
+
$content_range = preg_split('/[^0-9]+/', $_SERVER['HTTP_CONTENT_RANGE']);
|
485 |
+
$size = $content_range ? $content_range[3] : null;
|
486 |
+
}
|
487 |
+
|
488 |
+
$attachments = array();
|
489 |
+
$files = wpbdp_flatten_files_array( isset( $_FILES['images'] ) ? $_FILES['images'] : array() );
|
490 |
+
$errors = array();
|
491 |
+
|
492 |
+
foreach ( $files as $i => $file ) {
|
493 |
+
$image_error = '';
|
494 |
+
$attachment_id = wpbdp_media_upload( $file,
|
495 |
+
true,
|
496 |
+
true,
|
497 |
+
array( 'image' => true,
|
498 |
+
'max-size' => intval( wpbdp_get_option( 'image-max-filesize' ) ) * 1024 ),
|
499 |
+
$image_error ); // TODO: handle errors.
|
500 |
+
|
501 |
+
if ( $image_error )
|
502 |
+
$errors[ $file['name'] ] = $image_error;
|
503 |
+
else
|
504 |
+
$attachments[] = $attachment_id;
|
505 |
+
}
|
506 |
+
|
507 |
+
$html = '';
|
508 |
+
foreach ( $attachments as $attachment_id ) {
|
509 |
+
if ( $state )
|
510 |
+
$state->images[] = $attachment_id;
|
511 |
+
|
512 |
+
$html .= wpbdp_render( 'submit-listing/images-single',
|
513 |
+
array( 'image_id' => $attachment_id,
|
514 |
+
'state_id' => $state ? $state->id : '' ),
|
515 |
+
false );
|
516 |
+
}
|
517 |
+
|
518 |
+
if ( $listing_id ) {
|
519 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
520 |
+
$listing->set_images( $attachments, true );
|
521 |
+
} elseif ( $state ) {
|
522 |
+
$state->save();
|
523 |
+
}
|
524 |
+
|
525 |
+
if ( $errors ) {
|
526 |
+
$error_msg = '';
|
527 |
+
|
528 |
+
foreach ( $errors as $fname => $error )
|
529 |
+
$error_msg .= sprintf( '• %s: %s', $fname, $error ) . '<br />';
|
530 |
+
|
531 |
+
$res->add( 'uploadErrors', $error_msg );
|
532 |
+
}
|
533 |
+
|
534 |
+
$res->add( 'attachmentIds', $attachments );
|
535 |
+
$res->add( 'html', $html );
|
536 |
+
$res->send();
|
537 |
+
}
|
538 |
+
|
539 |
+
public function ajax_listing_submit_image_delete() {
|
540 |
+
$res = new WPBDP_Ajax_Response();
|
541 |
+
$image_id = intval( $_REQUEST['image_id'] );
|
542 |
+
|
543 |
+
if ( ! $image_id )
|
544 |
+
$res->send_error();
|
545 |
+
|
546 |
+
$state_id = isset( $_REQUEST['state_id'] ) ? $_REQUEST['state_id'] : '';
|
547 |
+
|
548 |
+
if ( $state_id ) {
|
549 |
+
require_once( WPBDP_PATH . 'core/view-submit-listing.php' );
|
550 |
+
|
551 |
+
if ( ! $state_id )
|
552 |
+
$res->send_error();
|
553 |
+
|
554 |
+
$state = WPBDP_Listing_Submit_State::get( $state_id );
|
555 |
+
|
556 |
+
if ( ! $state || ! in_array( $image_id, $state->images ) )
|
557 |
+
$res->send_error();
|
558 |
+
|
559 |
+
wpbdp_array_remove_value( $state->images, $image_id );
|
560 |
+
$state->save();
|
561 |
+
}
|
562 |
+
|
563 |
+
wp_delete_attachment( $image_id, true );
|
564 |
+
|
565 |
+
$res->add( 'imageId', $image_id );
|
566 |
+
$res->send();
|
567 |
+
}
|
568 |
+
|
569 |
+
private function get_shortcodes() {
|
570 |
+
$shortcodes = array();
|
571 |
+
$shortcodes += array_fill_keys( array( 'WPBUSDIRMANADDLISTING',
|
572 |
+
'businessdirectory-submitlisting' ),
|
573 |
+
array( &$this->controller, 'submit_listing' ) );
|
574 |
+
$shortcodes += array_fill_keys( array( 'WPBUSDIRMANMANAGELISTING',
|
575 |
+
'businessdirectory-managelistings',
|
576 |
+
'businessdirectory-manage_listings' ),
|
577 |
+
array( &$this->controller, 'manage_listings' ) );
|
578 |
+
$shortcodes += array_fill_keys( array( 'WPBUSDIRMANVIEWLISTINGS',
|
579 |
+
'WPBUSDIRMANMVIEWLISTINGS',
|
580 |
+
'businessdirectory-view_listings',
|
581 |
+
'businessdirectory-viewlistings',
|
582 |
+
'businessdirectory-listings' ),
|
583 |
+
array( &$this, '_listings_shortcode' ) );
|
584 |
+
$shortcodes += array_fill_keys( array( 'WPBUSDIRMANUI',
|
585 |
+
'businessdirectory',
|
586 |
+
'business-directory' ),
|
587 |
+
array( &$this->controller, 'dispatch' ) );
|
588 |
+
$shortcodes += array_fill_keys( array( 'businessdirectory-search',
|
589 |
+
'businessdirectory_search' ),
|
590 |
+
array( &$this->controller, 'search' ) );
|
591 |
+
$shortcodes['businessdirectory-featuredlistings'] = array( &$this, '_featured_listings_shortcode' );
|
592 |
+
|
593 |
+
return apply_filters( 'wpbdp_shortcodes', $shortcodes );
|
594 |
+
}
|
595 |
+
|
596 |
+
public function _init_modules() {
|
597 |
+
do_action('wpbdp_modules_loaded');
|
598 |
+
do_action_ref_array( 'wpbdp_register_settings', array( &$this->settings ) );
|
599 |
+
do_action('wpbdp_register_fields', $this->formfields);
|
600 |
+
do_action('wpbdp_modules_init');
|
601 |
+
|
602 |
+
if ( wpbdp_get_option( 'tracking-on', false ) ) {
|
603 |
+
$this->site_tracking = new WPBDP_SiteTracking();
|
604 |
+
}
|
605 |
+
}
|
606 |
+
|
607 |
+
public function get_post_type() {
|
608 |
+
return WPBDP_POST_TYPE;
|
609 |
+
}
|
610 |
+
|
611 |
+
public function get_post_type_category() {
|
612 |
+
return WPBDP_CATEGORY_TAX;
|
613 |
+
}
|
614 |
+
|
615 |
+
public function get_post_type_tags() {
|
616 |
+
return WPBDP_TAGS_TAX;
|
617 |
+
}
|
618 |
+
|
619 |
+
public function install_or_update_plugin() {
|
620 |
+
$installer = new WPBDP_Installer();
|
621 |
+
$installer->install();
|
622 |
+
}
|
623 |
+
|
624 |
+
public function plugin_action_links( $links ) {
|
625 |
+
$links['settings'] = '<a href="' . admin_url( 'admin.php?page=wpbdp_admin_settings' ) . '">' . _x( 'Settings', 'admin plugins', 'WPBDM' ) . '</a>';
|
626 |
+
return $links;
|
627 |
+
}
|
628 |
+
|
629 |
+
function _register_post_type() {
|
630 |
+
$post_type_slug = $this->settings->get('permalinks-directory-slug', WPBDP_POST_TYPE);
|
631 |
+
$category_slug = $this->settings->get('permalinks-category-slug', WPBDP_CATEGORY_TAX);
|
632 |
+
$tags_slug = $this->settings->get('permalinks-tags-slug', WPBDP_TAGS_TAX);
|
633 |
+
|
634 |
+
$labels = array(
|
635 |
+
'name' => _x('Directory', 'post type general name', 'WPBDM'),
|
636 |
+
'singular_name' => _x('Directory', 'post type singular name', 'WPBDM'),
|
637 |
+
'add_new' => _x('Add New Listing', 'listing', 'WPBDM'),
|
638 |
+
'add_new_item' => _x('Add New Listing', 'post type', 'WPBDM'),
|
639 |
+
'edit_item' => __('Edit Listing', 'WPBDM'),
|
640 |
+
'new_item' => __('New Listing', 'WPBDM'),
|
641 |
+
'view_item' => __('View Listing', 'WPBDM'),
|
642 |
+
'search_items' => __('Search Listings', 'WPBDM'),
|
643 |
+
'not_found' => __('No listings found', 'WPBDM'),
|
644 |
+
'not_found_in_trash' => __('No listings found in trash', 'WPBDM'),
|
645 |
+
'parent_item_colon' => ''
|
646 |
+
);
|
647 |
+
|
648 |
+
$args = array(
|
649 |
+
'labels' => $labels,
|
650 |
+
'public' => true,
|
651 |
+
'publicly_queryable' => true,
|
652 |
+
'show_ui' => true,
|
653 |
+
'query_var' => true,
|
654 |
+
'rewrite' => array('slug'=> $post_type_slug, 'with_front' => false, 'feeds' => true),
|
655 |
+
'capability_type' => 'post',
|
656 |
+
'hierarchical' => false,
|
657 |
+
'menu_position' => null,
|
658 |
+
'menu_icon' => WPBDP_URL . 'admin/resources/menuico.png',
|
659 |
+
'supports' => array('title','editor','author','categories','tags','thumbnail','excerpt','comments','custom-fields','trackbacks')
|
660 |
+
);
|
661 |
+
|
662 |
+
register_post_type(WPBDP_POST_TYPE, $args);
|
663 |
+
|
664 |
+
register_taxonomy( WPBDP_CATEGORY_TAX, WPBDP_POST_TYPE,
|
665 |
+
array( 'hierarchical' => true,
|
666 |
+
'label' => __( 'Directory Categories', 'WPBDM'),
|
667 |
+
'singular_name' => 'Directory Category',
|
668 |
+
'show_in_nav_menus' => true,
|
669 |
+
'query_var' => true,
|
670 |
+
'rewrite' => array('slug' => $category_slug) ) );
|
671 |
+
register_taxonomy(WPBDP_TAGS_TAX, WPBDP_POST_TYPE, array( 'hierarchical' => false, 'label' => 'Directory Tags', 'singular_name' => 'Directory Tag', 'show_in_nav_menus' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array('slug' => $tags_slug) ) );
|
672 |
+
}
|
673 |
+
|
674 |
+
public function _register_image_sizes() {
|
675 |
+
$thumbnail_width = intval( wpbdp_get_option( 'thumbnail-width' ) );
|
676 |
+
|
677 |
+
$max_width = intval( wpbdp_get_option('image-max-width') );
|
678 |
+
$max_height = intval( wpbdp_get_option('image-max-height') );
|
679 |
+
|
680 |
+
// thumbnail size
|
681 |
+
add_image_size( 'wpbdp-thumb', $thumbnail_width, $max_height, false );
|
682 |
+
add_image_size( 'wpbdp-large', $max_width, $max_height, false );
|
683 |
+
}
|
684 |
+
|
685 |
+
public function handle_recaptcha() {
|
686 |
+
// Comments reCAPTCHA.
|
687 |
+
if ( wpbdp_get_option( 'recaptcha-for-comments' ) ) {
|
688 |
+
add_filter( 'comment_form_field_comment', array( &$this, 'recaptcha_in_comments' ) );
|
689 |
+
add_action( 'preprocess_comment', array( &$this, 'check_comment_recaptcha' ), 0 );
|
690 |
+
|
691 |
+
// add_action('wp_head', array(&$this, 'saved_comment'), 0);
|
692 |
+
add_action( 'comment_post_redirect', array( &$this, 'comment_relative_redirect' ), 0, 2 );
|
693 |
+
}
|
694 |
+
}
|
695 |
+
|
696 |
+
public function is_debug_on() {
|
697 |
+
return WPBDP_Debugging::is_debug_on();
|
698 |
+
}
|
699 |
+
|
700 |
+
public function debug_on() {
|
701 |
+
global $wpdb;
|
702 |
+
|
703 |
+
// Set MySQL strict mode.
|
704 |
+
//$wpdb->show_errors();
|
705 |
+
//$wpdb->query( "SET @@sql_mode = 'TRADITIONAL'" );
|
706 |
+
|
707 |
+
// Enable BD debugging.
|
708 |
+
WPBDP_Debugging::debug_on();
|
709 |
+
}
|
710 |
+
|
711 |
+
public function debug_off() {
|
712 |
+
WPBDP_Debugging::debug_off();
|
713 |
+
}
|
714 |
+
|
715 |
+
public function has_module($name) {
|
716 |
+
switch (strtolower($name)) {
|
717 |
+
default:
|
718 |
+
break;
|
719 |
+
case 'payfast':
|
720 |
+
case 'payfast-payment-module':
|
721 |
+
return class_exists( 'WPBDP_Gateways_PayFast' );
|
722 |
+
break;
|
723 |
+
case 'paypal':
|
724 |
+
case 'paypal-gateway-module':
|
725 |
+
return class_exists( 'WPBDP_Paypal_Module' );
|
726 |
+
break;
|
727 |
+
case '2checkout':
|
728 |
+
case 'twocheckout':
|
729 |
+
case '2checkout-gateway-module':
|
730 |
+
return class_exists( 'WPBDP_2Checkout_Module' );
|
731 |
+
break;
|
732 |
+
case 'googlecheckout':
|
733 |
+
return wpbdp_payments_api()->has_gateway('googlecheckout');
|
734 |
+
break;
|
735 |
+
case 'google-maps-module':
|
736 |
+
case 'googlemaps':
|
737 |
+
return class_exists('BusinessDirectory_GoogleMapsPlugin');
|
738 |
+
break;
|
739 |
+
case 'ratings-module':
|
740 |
+
case 'ratings':
|
741 |
+
return class_exists('BusinessDirectory_RatingsModule');
|
742 |
+
break;
|
743 |
+
case 'regions-module':
|
744 |
+
case 'regions':
|
745 |
+
return class_exists('WPBDP_RegionsPlugin');
|
746 |
+
break;
|
747 |
+
case 'file-attachments-module':
|
748 |
+
case 'attachments':
|
749 |
+
return class_exists( 'WPBDP_ListingAttachmentsModule' );
|
750 |
+
break;
|
751 |
+
case 'zip-search-module':
|
752 |
+
case 'zipcodesearch':
|
753 |
+
return class_exists( 'WPBDP_ZIPCodeSearchModule' );
|
754 |
+
break;
|
755 |
+
case 'featured-levels-module':
|
756 |
+
case 'featuredlevels':
|
757 |
+
return class_exists( 'WPBDP_FeaturedLevelsModule' );
|
758 |
+
break;
|
759 |
+
case 'stripe-payment-module':
|
760 |
+
case 'stripe':
|
761 |
+
return class_exists( 'WPBDP_Stripe_Module' );
|
762 |
+
break;
|
763 |
+
case 'categories':
|
764 |
+
return class_exists( 'WPBDP_CategoriesModule' );
|
765 |
+
break;
|
766 |
+
}
|
767 |
+
|
768 |
+
return false;
|
769 |
+
}
|
770 |
+
|
771 |
+
public function _rss_feed() {
|
772 |
+
$action = $this->controller->get_current_action();
|
773 |
+
$main_page_id = wpbdp_get_page_id( 'main' );
|
774 |
+
|
775 |
+
if ( !$action || !$main_page_id )
|
776 |
+
return;
|
777 |
+
|
778 |
+
echo "\n<!-- Business Directory RSS feed -->\n";
|
779 |
+
echo sprintf( '<link rel="alternate" type="application/rss+xml" title="%s" href="%s" /> ',
|
780 |
+
sprintf( _x( '%s Feed', 'rss feed', 'WPBDM'), get_the_title( $main_page_id ) ),
|
781 |
+
esc_url( add_query_arg( 'post_type', WPBDP_POST_TYPE, get_bloginfo( 'rss2_url' ) ) )
|
782 |
+
);
|
783 |
+
|
784 |
+
if ( $action == 'browsetag' || $action == 'browsecategory' ) {
|
785 |
+
echo "\n";
|
786 |
+
echo sprintf( '<link rel="alternate" type="application/rss+xml" title="%s" href="%s" /> ',
|
787 |
+
sprintf( _x( '%s Feed', 'rss feed', 'WPBDM'), get_the_title( $main_page_id ) ),
|
788 |
+
esc_url( add_query_arg( array( 'post_type' => WPBDP_POST_TYPE, WPBDP_CATEGORY_TAX => get_query_var( 'category' ) ), get_bloginfo( 'rss2_url' ) ) )
|
789 |
+
);
|
790 |
+
}
|
791 |
+
|
792 |
+
echo "\n";
|
793 |
+
}
|
794 |
+
|
795 |
+
public function _register_widgets() {
|
796 |
+
include_once ( WPBDP_PATH . 'core/widget-featured-listings.php' );
|
797 |
+
include_once ( WPBDP_PATH . 'core/widget-latest-listings.php' );
|
798 |
+
include_once ( WPBDP_PATH . 'core/widget-random-listings.php' );
|
799 |
+
include_once ( WPBDP_PATH . 'core/widget-search.php' );
|
800 |
+
|
801 |
+
register_widget('WPBDP_FeaturedListingsWidget');
|
802 |
+
register_widget('WPBDP_LatestListingsWidget');
|
803 |
+
register_widget('WPBDP_RandomListingsWidget');
|
804 |
+
register_widget('WPBDP_SearchWidget');
|
805 |
+
}
|
806 |
+
|
807 |
+
public function _listings_shortcode($atts) {
|
808 |
+
if (!$this->controller->check_main_page($msg)) return $msg;
|
809 |
+
|
810 |
+
$atts = shortcode_atts( array(
|
811 |
+
'category' => null,
|
812 |
+
'operator' => 'OR'
|
813 |
+
),
|
814 |
+
$atts
|
815 |
+
);
|
816 |
+
|
817 |
+
if ( !$atts['category'] )
|
818 |
+
return $this->controller->view_listings( true );
|
819 |
+
|
820 |
+
$atts['category'] = explode( ',', $atts['category'] );
|
821 |
+
$categories = array();
|
822 |
+
|
823 |
+
foreach ( $atts['category'] as $cat ) {
|
824 |
+
$term = null;
|
825 |
+
if ( !is_numeric( $cat ) )
|
826 |
+
$term = get_term_by( 'slug', $cat, WPBDP_CATEGORY_TAX );
|
827 |
+
|
828 |
+
if ( !$term && is_numeric( $cat ) )
|
829 |
+
$term = get_term_by( 'id', $cat, WPBDP_CATEGORY_TAX );
|
830 |
+
|
831 |
+
if ( $term )
|
832 |
+
$categories[] = $term->term_id;
|
833 |
+
}
|
834 |
+
|
835 |
+
return $this->controller->browse_category( $categories, array(), true );
|
836 |
+
}
|
837 |
+
|
838 |
+
public function _featured_listings_shortcode($atts) {
|
839 |
+
if (!$this->controller->check_main_page($msg)) return $msg;
|
840 |
+
|
841 |
+
$atts = shortcode_atts( array(
|
842 |
+
'number_of_listings' => wpbdp_get_option( 'listings-per-page' )
|
843 |
+
),
|
844 |
+
$atts
|
845 |
+
);
|
846 |
+
$atts['number_of_listings'] = max( 0, intval( $atts['number_of_listings'] ) );
|
847 |
+
|
848 |
+
return $this->controller->view_featured_listings( $atts );
|
849 |
+
}
|
850 |
+
|
851 |
+
/* theme filters */
|
852 |
+
public function _comments_template($template) {
|
853 |
+
// disable comments in WPBDP pages or if comments are disabled for listings
|
854 |
+
if ( (is_single() && get_post_type() == WPBDP_POST_TYPE && !$this->settings->get('show-comment-form')) ||
|
855 |
+
(get_post_type() == 'page' && get_the_ID() == wpbdp_get_page_id('main') ) ) {
|
856 |
+
return WPBDP_TEMPLATES_PATH . '/empty-template.php';
|
857 |
+
}
|
858 |
+
|
859 |
+
return $template;
|
860 |
+
}
|
861 |
+
|
862 |
+
public function _category_template($template) {
|
863 |
+
if (get_query_var(WPBDP_CATEGORY_TAX) && taxonomy_exists(WPBDP_CATEGORY_TAX)) {
|
864 |
+
return wpbdp_locate_template(array('businessdirectory-category', 'wpbusdirman-category'));
|
865 |
+
}
|
866 |
+
|
867 |
+
return $template;
|
868 |
+
}
|
869 |
+
|
870 |
+
public function _single_template($template) {
|
871 |
+
if (is_single() && get_post_type() == WPBDP_POST_TYPE) {
|
872 |
+
return wpbdp_locate_template(array('businessdirectory-single', 'wpbusdirman-single'));
|
873 |
+
}
|
874 |
+
|
875 |
+
return $template;
|
876 |
+
}
|
877 |
+
|
878 |
+
/* scripts & styles */
|
879 |
+
|
880 |
+
/**
|
881 |
+
* Registers scripts and styles that can be used either by frontend or backend code.
|
882 |
+
* The scripts are just registered, not enqueued.
|
883 |
+
*
|
884 |
+
* @since 3.4
|
885 |
+
*/
|
886 |
+
public function register_common_scripts() {
|
887 |
+
// jQuery-FileUpload.
|
888 |
+
// wp_register_script( 'jquery-fileupload-ui-widget',
|
889 |
+
// WPBDP_URL . 'vendors/jQuery-File-Upload-9.5.7/js/vendor/jquery.ui.widget' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.js' );
|
890 |
+
wp_register_script( 'jquery-fileupload-iframe-transport',
|
891 |
+
WPBDP_URL . 'vendors/jQuery-File-Upload-9.5.7/js/jquery.iframe-transport' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.js' );
|
892 |
+
wp_register_script( 'jquery-fileupload',
|
893 |
+
WPBDP_URL . 'vendors/jQuery-File-Upload-9.5.7/js/jquery.fileupload' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.js',
|
894 |
+
array( 'jquery',
|
895 |
+
'jquery-ui-widget',
|
896 |
+
'jquery-fileupload-iframe-transport' ) );
|
897 |
+
|
898 |
+
// Drag & Drop.
|
899 |
+
wp_register_style( 'wpbdp-dnd-upload', WPBDP_URL . 'core/css/dnd-upload' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.css' );
|
900 |
+
wp_register_script( 'wpbdp-dnd-upload', WPBDP_URL . 'core/js/dnd-upload' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.js',
|
901 |
+
array( 'jquery-fileupload' ) );
|
902 |
+
}
|
903 |
+
|
904 |
+
public function is_plugin_page() {
|
905 |
+
global $post;
|
906 |
+
|
907 |
+
if ( $post && 'page' == $post->post_type ) {
|
908 |
+
foreach ( array_keys( $this->get_shortcodes() ) as $shortcode ) {
|
909 |
+
if ( wpbdp_has_shortcode( $post->post_content, $shortcode ) ) {
|
910 |
+
return true;
|
911 |
+
break;
|
912 |
+
}
|
913 |
+
}
|
914 |
+
}
|
915 |
+
|
916 |
+
if ( $post && WPBDP_POST_TYPE == $post->post_type )
|
917 |
+
return true;
|
918 |
+
|
919 |
+
if ( 'template' == _wpbdp_template_mode ('single' ) || 'template' == _wpbdp_template_mode( 'category' ) )
|
920 |
+
return true;
|
921 |
+
// TODO: $is_plugin_page detection should take into account custom post type/tax templates.
|
922 |
+
|
923 |
+
return false;
|
924 |
+
}
|
925 |
+
|
926 |
+
public function _enqueue_scripts() {
|
927 |
+
$only_in_plugin_pages = true;
|
928 |
+
|
929 |
+
wp_enqueue_style( 'wpbdp-widgets', WPBDP_URL . 'core/css/widgets.min.css' );
|
930 |
+
|
931 |
+
if ( $only_in_plugin_pages && ! $this->is_plugin_page() )
|
932 |
+
return;
|
933 |
+
|
934 |
+
if ( $this->is_debug_on() ) {
|
935 |
+
wp_register_style( 'wpbdp-base-css', WPBDP_URL . 'core/css/wpbdp.css' );
|
936 |
+
wp_register_script( 'wpbdp-js', WPBDP_URL . 'core/js/wpbdp.js', array( 'jquery' ) );
|
937 |
+
} else {
|
938 |
+
wp_register_style( 'wpbdp-base-css', WPBDP_URL . 'core/css/wpbdp.min.css' );
|
939 |
+
wp_register_script( 'wpbdp-js', WPBDP_URL . 'core/js/wpbdp.min.js', array( 'jquery' ) );
|
940 |
+
}
|
941 |
+
|
942 |
+
wp_enqueue_style( 'wpbdp-dnd-upload' );
|
943 |
+
wp_enqueue_script( 'wpbdp-dnd-upload' );
|
944 |
+
|
945 |
+
if ( wpbdp_get_option( 'use-thickbox' ) ) {
|
946 |
+
add_thickbox();
|
947 |
+
}
|
948 |
+
|
949 |
+
wp_enqueue_style( 'wpbdp-base-css' );
|
950 |
+
wp_enqueue_script( 'wpbdp-js' );
|
951 |
+
|
952 |
+
if ( wpbdp_get_option( 'payments-on') && wpbdp_get_option( 'googlewallet' ) ) {
|
953 |
+
wp_enqueue_script( 'wpbdp-googlewallet', WPBDP_URL . 'core/js/googlewallet' . ( ! $this->is_debug_on() ? '.min' : '' ) . '.js', array( 'wpbdp-js' ) );
|
954 |
+
}
|
955 |
+
|
956 |
+
do_action( 'wpbdp_enqueue_scripts' );
|
957 |
+
|
958 |
+
// enable legacy css (should be removed in a future release) XXX
|
959 |
+
if (_wpbdp_template_mode('single') == 'template' || _wpbdp_template_mode('category') == 'template' )
|
960 |
+
wp_enqueue_style('wpbdp-legacy-css', WPBDP_URL . 'core/css/wpbdp-legacy.min.css');
|
961 |
+
}
|
962 |
+
|
963 |
+
/**
|
964 |
+
* @since 3.5.3
|
965 |
+
*/
|
966 |
+
public function enqueue_css_override() {
|
967 |
+
$stylesheet_dir = trailingslashit( get_stylesheet_directory() );
|
968 |
+
$stylesheet_dir_uri = trailingslashit( get_stylesheet_directory_uri() );
|
969 |
+
$template_dir = trailingslashit( get_template_directory() );
|
970 |
+
$template_dir_uri = trailingslashit( get_template_directory_uri() );
|
971 |
+
|
972 |
+
$folders_uris = array(
|
973 |
+
array( trailingslashit( WP_PLUGIN_DIR ), trailingslashit( WP_PLUGIN_URL ) ),
|
974 |
+
array( $stylesheet_dir, $stylesheet_dir_uri ),
|
975 |
+
array( $stylesheet_dir . 'css/', $stylesheet_dir_uri . 'css/' )
|
976 |
+
);
|
977 |
+
|
978 |
+
if ( $template_dir != $stylesheet_dir ) {
|
979 |
+
$folders_uris[] = array( $template_dir, $template_dir_uri );
|
980 |
+
$folders_uris[] = array( $template_dir . 'css/', $template_dir_uri . 'css/' );
|
981 |
+
}
|
982 |
+
|
983 |
+
$filenames = array( 'wpbdp.css',
|
984 |
+
'wpbusdirman.css',
|
985 |
+
'wpbdp_custom_style.css',
|
986 |
+
'wpbdp_custom_styles.css',
|
987 |
+
'wpbdm_custom_style.css',
|
988 |
+
'wpbdm_custom_styles.css' );
|
989 |
+
|
990 |
+
$n = 0;
|
991 |
+
foreach ( $folders_uris as $folder_uri ) {
|
992 |
+
list( $dir, $uri ) = $folder_uri;
|
993 |
+
|
994 |
+
foreach ( $filenames as $f ) {
|
995 |
+
if ( file_exists( $dir . $f ) ) {
|
996 |
+
wp_enqueue_style( 'wpbdp-custom-' . $n, $uri . $f );
|
997 |
+
$n++;
|
998 |
+
}
|
999 |
+
}
|
1000 |
+
}
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
/*
|
1004 |
+
* Page metadata
|
1005 |
+
*/
|
1006 |
+
public function _meta_setup() {
|
1007 |
+
$action = $this->controller->get_current_action();
|
1008 |
+
|
1009 |
+
if ( ! $action )
|
1010 |
+
return;
|
1011 |
+
|
1012 |
+
require_once( WPBDP_PATH . 'core/class-page-meta.php' );
|
1013 |
+
$this->page_meta = new WPBDP_Page_Meta( $action );
|
1014 |
+
|
1015 |
+
|
1016 |
+
$this->_do_wpseo = defined( 'WPSEO_VERSION' ) ? true : false;
|
1017 |
+
|
1018 |
+
if ( $this->_do_wpseo ) {
|
1019 |
+
global $wpseo_front;
|
1020 |
+
|
1021 |
+
remove_filter( 'wp_title', array( $this, '_meta_title' ), 10, 3 );
|
1022 |
+
add_filter( 'wp_title', array( $this, '_meta_title' ), 16, 3 );
|
1023 |
+
|
1024 |
+
remove_filter( 'wp_title', array( &$wpseo_front, 'title' ), 15, 3 );
|
1025 |
+
remove_action( 'wp_head', array( &$wpseo_front, 'head' ), 1, 1 );
|
1026 |
+
add_action( 'wp_head', array( $this, '_meta_keywords' ) );
|
1027 |
+
}
|
1028 |
+
|
1029 |
+
remove_filter( 'wp_head', 'rel_canonical' );
|
1030 |
+
add_filter( 'wp_head', array( $this, '_meta_rel_canonical' ) );
|
1031 |
+
|
1032 |
+
if ( 'showlisting' == $action && wpbdp_rewrite_on() )
|
1033 |
+
add_action( 'wp_head', array( &$this, 'listing_opentags' ) );
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
/*
|
1037 |
+
* Fix issues with Jetpack.
|
1038 |
+
*/
|
1039 |
+
public function _jetpack_compat( &$wp ) {
|
1040 |
+
static $incompatible_actions = array( 'submitlisting', 'editlisting', 'upgradetostickylisting' );
|
1041 |
+
|
1042 |
+
$action = $this->controller->get_current_action();
|
1043 |
+
|
1044 |
+
if ( !$action )
|
1045 |
+
return;
|
1046 |
+
|
1047 |
+
if ( defined( 'JETPACK__VERSION' ) && in_array( $action, $incompatible_actions ) ) {
|
1048 |
+
add_filter( 'jetpack_enable_opengraph', '__return_false', 99 );
|
1049 |
+
remove_action( 'wp_head', 'jetpack_og_tags' );
|
1050 |
+
}
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
public function _handle_broken_plugin_filters() {
|
1054 |
+
$action = $this->controller->get_current_action();
|
1055 |
+
|
1056 |
+
if ( !$action )
|
1057 |
+
return;
|
1058 |
+
|
1059 |
+
// Relevanssi
|
1060 |
+
if ( in_array( $action, array( 'submitlisting', 'editlisting' ), true ) && function_exists( 'relevanssi_insert_edit' ) ) {
|
1061 |
+
remove_action( 'wp_insert_post', 'relevanssi_insert_edit', 99, 1 );
|
1062 |
+
remove_action( 'delete_attachment', 'relevanssi_delete' );
|
1063 |
+
remove_action( 'add_attachment', 'relevanssi_publish' );
|
1064 |
+
remove_action( 'edit_attachment', 'relevanssi_edit' );
|
1065 |
+
}
|
1066 |
+
|
1067 |
+
$bad_filters = array( 'get_the_excerpt' => array(), 'the_excerpt' => array(), 'the_content' => array() );
|
1068 |
+
|
1069 |
+
// AddThis Social Bookmarking Widget - http://www.addthis.com/
|
1070 |
+
if ( defined( 'ADDTHIS_PLUGIN_VERSION' ) ) {
|
1071 |
+
$bad_filters['get_the_excerpt'][] = array( 'addthis_display_social_widget_excerpt', 11);
|
1072 |
+
$bad_filters['get_the_excerpt'][] = array( 'addthis_display_social_widget', 15 );
|
1073 |
+
$bad_filters['the_content'][] = array( 'addthis_display_social_widget', 15 );
|
1074 |
+
}
|
1075 |
+
|
1076 |
+
// Jamie Social Icons - http://wordpress.org/extend/plugins/jamie-social-icons/
|
1077 |
+
if ( function_exists( 'jamiesocial' ) ) {
|
1078 |
+
$bad_filters['the_content'][] = 'add_post_topbot_content';
|
1079 |
+
$bad_filters['the_content'][] = 'add_post_bot_content';
|
1080 |
+
$bad_filters['the_content'][] = 'add_page_topbot_content';
|
1081 |
+
$bad_filters['the_content'][] = 'add_page_top_content';
|
1082 |
+
$bad_filters['the_content'][] = 'add_page_bot_content';
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
// TF Social Share - http://www.searchtechword.com/2011/06/wordpress-plugin-add-twitter-facebook-google-plus-one-share
|
1086 |
+
if ( function_exists( 'kc_twitter_facebook_excerpt' ) ) {
|
1087 |
+
$bad_filters['the_excerpt'][] = 'kc_twitter_facebook_excerpt';
|
1088 |
+
$bad_filters['the_content'][] = 'kc_twitter_facebook_contents';
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
// Shareaholic - https://shareaholic.com/publishers/
|
1092 |
+
if ( defined( 'SHRSB_vNum' ) ) {
|
1093 |
+
$bad_filters['the_content'][] = 'shrsb_position_menu';
|
1094 |
+
$bad_filters['the_content'][] = 'shrsb_get_recommendations';
|
1095 |
+
$bad_filters['the_content'][] = 'shrsb_get_cb';
|
1096 |
+
}
|
1097 |
+
|
1098 |
+
// Simple Facebook Connect (#481)
|
1099 |
+
if ( function_exists( 'sfc_version' ) ) {
|
1100 |
+
remove_action( 'wp_head', 'sfc_base_meta' );
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
// Quick AdSense - http://quicksense.net/
|
1104 |
+
global $QData;
|
1105 |
+
if ( isset( $QData ) ) {
|
1106 |
+
$bad_filters['the_content'][] = 'process_content';
|
1107 |
+
}
|
1108 |
+
|
1109 |
+
foreach ( $bad_filters as $filter => &$callbacks ) {
|
1110 |
+
foreach ( $callbacks as &$callback_info ) {
|
1111 |
+
if ( has_filter( $filter, is_array( $callback_info ) ? $callback_info[0] : $callback_info ) ) {
|
1112 |
+
remove_filter( $filter, is_array( $callback_info ) ? $callback_info[0] : $callback_info, is_array( $callback_info ) ? $callback_info[1] : 10 );
|
1113 |
+
}
|
1114 |
+
}
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
// TODO: it'd be nice to move workarounds outside this class.
|
1120 |
+
public function _meta_title( $title = '', $sep = '»', $seplocation = 'right' ) {
|
1121 |
+
$action = $this->controller->get_current_action();
|
1122 |
+
|
1123 |
+
switch ($action) {
|
1124 |
+
case 'submitlisting':
|
1125 |
+
if ( $this->_do_wpseo ) {
|
1126 |
+
$title = esc_html( strip_tags( stripslashes( apply_filters( 'wpseo_title', $title ) ) ) );
|
1127 |
+
return $title;
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
return _x( 'Submit A Listing', 'title', 'WPBDM' ) . ' ' . $sep . ' ' . $title;
|
1131 |
+
|
1132 |
+
break;
|
1133 |
+
|
1134 |
+
case 'search':
|
1135 |
+
if ( $this->_do_wpseo ) {
|
1136 |
+
$title = esc_html( strip_tags( stripslashes( apply_filters( 'wpseo_title', $title ) ) ) );
|
1137 |
+
return $title;
|
1138 |
+
}
|
1139 |
+
|
1140 |
+
return _x( 'Find a Listing', 'title', 'WPBDM' ) . ' ' . $sep . ' ' . $title;
|
1141 |
+
|
1142 |
+
break;
|
1143 |
+
|
1144 |
+
case 'viewlistings':
|
1145 |
+
if ( $this->_do_wpseo ) {
|
1146 |
+
$title = esc_html( strip_tags( stripslashes( apply_filters( 'wpseo_title', $title ) ) ) );
|
1147 |
+
return $title;
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
return _x( 'View All Listings', 'title', 'WPBDM' ) . ' ' . $sep . ' ' . $title;
|
1151 |
+
break;
|
1152 |
+
|
1153 |
+
case 'browsetag':
|
1154 |
+
$term = get_term_by('slug', get_query_var('tag'), WPBDP_TAGS_TAX);
|
1155 |
+
|
1156 |
+
if ( $this->_do_wpseo ) {
|
1157 |
+
global $wpseo_front;
|
1158 |
+
|
1159 |
+
if ( method_exists( 'WPSEO_Taxonomy_Meta', 'get_term_meta' ) ) {
|
1160 |
+
$title = WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'title' );
|
1161 |
+
} else {
|
1162 |
+
$title = trim( wpseo_get_term_meta( $term, $term->taxonomy, 'title' ) );
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
if ( !empty( $title ) )
|
1166 |
+
return wpseo_replace_vars( $title, (array) $term );
|
1167 |
+
|
1168 |
+
return $wpseo_front->get_title_from_options( 'title-tax-' . $term->taxonomy, $term );
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
return sprintf( _x( 'Listings tagged: %s', 'title', 'WPBDM' ), $term->name ) . ' ' . $sep . ' ' . $title;
|
1172 |
+
|
1173 |
+
break;
|
1174 |
+
|
1175 |
+
case 'browsecategory':
|
1176 |
+
$term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX);
|
1177 |
+
if (!$term && get_query_var('category_id')) $term = get_term_by('id', get_query_var('category_id'), WPBDP_CATEGORY_TAX);
|
1178 |
+
|
1179 |
+
if ( $this->_do_wpseo ) {
|
1180 |
+
global $wpseo_front;
|
1181 |
+
|
1182 |
+
if ( method_exists( 'WPSEO_Taxonomy_Meta', 'get_term_meta' ) ) {
|
1183 |
+
$title = WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'title' );
|
1184 |
+
} else {
|
1185 |
+
$title = trim( wpseo_get_term_meta( $term, $term->taxonomy, 'title' ) );
|
1186 |
+
}
|
1187 |
+
|
1188 |
+
if ( !empty( $title ) )
|
1189 |
+
return wpseo_replace_vars( $title, (array) $term );
|
1190 |
+
|
1191 |
+
return $wpseo_front->get_title_from_options( 'title-tax-' . $term->taxonomy, $term );
|
1192 |
+
}
|
1193 |
+
|
1194 |
+
return $term->name . ' ' . $sep . ' ' . $title;
|
1195 |
+
|
1196 |
+
break;
|
1197 |
+
|
1198 |
+
case 'showlisting':
|
1199 |
+
$listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
|
1200 |
+
|
1201 |
+
if ( $this->_do_wpseo ) {
|
1202 |
+
global $wpseo_front;
|
1203 |
+
|
1204 |
+
$title = $wpseo_front->get_content_title( get_post( $listing_id ) );
|
1205 |
+
$title = esc_html( strip_tags( stripslashes( apply_filters( 'wpseo_title', $title ) ) ) );
|
1206 |
+
|
1207 |
+
return $title;
|
1208 |
+
break;
|
1209 |
+
} else {
|
1210 |
+
$post_title = get_the_title($listing_id);
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
return $post_title . ' '. $sep . ' ' . $title;
|
1214 |
+
break;
|
1215 |
+
|
1216 |
+
case 'main':
|
1217 |
+
break;
|
1218 |
+
|
1219 |
+
default:
|
1220 |
+
break;
|
1221 |
+
}
|
1222 |
+
|
1223 |
+
return $title;
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
public function _meta_keywords() {
|
1227 |
+
global $wpseo_front;
|
1228 |
+
|
1229 |
+
$current_action = $this->controller->get_current_action();
|
1230 |
+
|
1231 |
+
switch ( $current_action ){
|
1232 |
+
case 'showlisting':
|
1233 |
+
global $post;
|
1234 |
+
|
1235 |
+
$listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
|
1236 |
+
|
1237 |
+
$prev_post = $post;
|
1238 |
+
$post = get_post( $listing_id );
|
1239 |
+
|
1240 |
+
$wpseo_front->metadesc();
|
1241 |
+
$wpseo_front->metakeywords();
|
1242 |
+
|
1243 |
+
$post = $prev_post;
|
1244 |
+
|
1245 |
+
break;
|
1246 |
+
case 'browsecategory':
|
1247 |
+
case 'browsetag':
|
1248 |
+
if ( $current_action == 'browsetag' ) {
|
1249 |
+
$term = get_term_by('slug', get_query_var('tag'), WPBDP_TAGS_TAX);
|
1250 |
+
} else {
|
1251 |
+
$term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX);
|
1252 |
+
if (!$term && get_query_var('category_id')) $term = get_term_by('id', get_query_var('category_id'), WPBDP_CATEGORY_TAX);
|
1253 |
+
}
|
1254 |
+
|
1255 |
+
if ( $term ) {
|
1256 |
+
$metadesc = method_exists( 'WPSEO_Taxonomy_Meta', 'get_term_meta' ) ?
|
1257 |
+
WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'desc' ) :
|
1258 |
+
wpseo_get_term_meta( $term, $term->taxonomy, 'desc' );
|
1259 |
+
if ( !$metadesc && isset( $wpseo_front->options['metadesc-tax-' . $term->taxonomy] ) )
|
1260 |
+
$metadesc = wpseo_replace_vars( $wpseo_front->options['metadesc-tax-' . $term->taxonomy], (array) $term );
|
1261 |
+
|
1262 |
+
if ( $metadesc )
|
1263 |
+
echo '<meta name="description" content="' . esc_attr( strip_tags( stripslashes( $metadesc ) ) ) . '"/>' . "\n";
|
1264 |
+
}
|
1265 |
+
|
1266 |
+
break;
|
1267 |
+
|
1268 |
+
case 'main':
|
1269 |
+
$wpseo_front->metadesc();
|
1270 |
+
$wpseo_front->metakeywords();
|
1271 |
+
|
1272 |
+
break;
|
1273 |
+
|
1274 |
+
default:
|
1275 |
+
break;
|
1276 |
+
}
|
1277 |
+
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
public function _meta_rel_canonical() {
|
1281 |
+
$action = $this->controller->get_current_action();
|
1282 |
+
|
1283 |
+
if ( !$action )
|
1284 |
+
return rel_canonical();
|
1285 |
+
|
1286 |
+
if ( in_array( $action, array( 'editlisting', 'submitlisting', 'sendcontactmessage', 'deletelisting', 'upgradetostickylisting', 'renewlisting' ) ) )
|
1287 |
+
return;
|
1288 |
+
|
1289 |
+
if ( $action == 'showlisting' ) {
|
1290 |
+
$listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
|
1291 |
+
$link = get_permalink( $listing_id );
|
1292 |
+
} else {
|
1293 |
+
$link = $_SERVER['REQUEST_URI'];
|
1294 |
+
}
|
1295 |
+
|
1296 |
+
echo sprintf( '<link rel="canonical" href="%s" />', esc_url( $link ) );
|
1297 |
+
}
|
1298 |
+
|
1299 |
+
function listing_opentags() {
|
1300 |
+
$listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
|
1301 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
1302 |
+
|
1303 |
+
if ( ! $listing )
|
1304 |
+
return;
|
1305 |
+
|
1306 |
+
echo '<meta property="og:type" content="website" />';
|
1307 |
+
echo '<meta property="og:title" content="' . esc_attr( WPBDP_SEO::listing_title( $listing_id ) ) . '" />';
|
1308 |
+
echo '<meta property="og:url" content="' . esc_url( $listing->get_permalink() ) . '" />';
|
1309 |
+
echo '<meta property="og:description" content="' . esc_attr( WPBDP_SEO::listing_og_description( $listing_id ) ) . '" />';
|
1310 |
+
|
1311 |
+
if ( $thumbnail_id = $listing->get_thumbnail_id() ) {
|
1312 |
+
if ( $img = wp_get_attachment_image_src( $thumbnail_id, 'wpbdp-large' ) )
|
1313 |
+
echo '<meta property="og:image" content="' . $img[0] . '" />';
|
1314 |
+
}
|
1315 |
+
}
|
1316 |
+
|
1317 |
+
public function ajax_file_field_upload() {
|
1318 |
+
echo '<form action="" method="POST" enctype="multipart/form-data">';
|
1319 |
+
echo '<input type="file" name="file" class="file-upload" onchange="return window.parent.WPBDP.fileUpload.handleUpload(this);"/>';
|
1320 |
+
echo '</form>';
|
1321 |
+
|
1322 |
+
if ( isset($_FILES['file']) && $_FILES['file']['error'] == 0 ) {
|
1323 |
+
// TODO: we support only images for now but we could use this for anything later
|
1324 |
+
if ( $media_id = wpbdp_media_upload( $_FILES['file'], true, true, array(), $errors ) ) {
|
1325 |
+
echo '<div class="preview" style="display: none;">';
|
1326 |
+
echo wp_get_attachment_image( $media_id, 'thumb', false );
|
1327 |
+
echo '</div>';
|
1328 |
+
|
1329 |
+
echo '<script type="text/javascript">';
|
1330 |
+
echo sprintf( 'window.parent.WPBDP.fileUpload.finishUpload(%d, %d);', $_REQUEST['field_id'], $media_id );
|
1331 |
+
echo '</script>';
|
1332 |
+
} else {
|
1333 |
+
print $errors;
|
1334 |
+
}
|
1335 |
+
}
|
1336 |
+
|
1337 |
+
echo sprintf( '<script type="text/javascript">window.parent.WPBDP.fileUpload.resizeIFrame(%d);</script>', $_REQUEST['field_id'] );
|
1338 |
+
|
1339 |
+
exit;
|
1340 |
+
}
|
1341 |
+
|
1342 |
+
/* Listing expiration. */
|
1343 |
+
public function _notify_expiring_listings() {
|
1344 |
+
global $wpdb;
|
1345 |
+
|
1346 |
+
if ( ! wpbdp_get_option( 'listing-renewal' ) )
|
1347 |
+
return;
|
1348 |
+
|
1349 |
+
wpbdp_log('Running expirations hook.');
|
1350 |
+
|
1351 |
+
$now = current_time( 'timestamp' );
|
1352 |
+
|
1353 |
+
$api = wpbdp_listings_api();
|
1354 |
+
$api->notify_expiring_listings( 0, $now ); // notify already expired listings first
|
1355 |
+
$api->notify_expiring_listings( wpbdp_get_option( 'renewal-email-threshold', 5 ), $now ); // notify listings expiring soon
|
1356 |
+
|
1357 |
+
if ( wpbdp_get_option( 'renewal-reminder' ) ) {
|
1358 |
+
$threshold = -max( 1, intval( wpbdp_get_option( 'renewal-reminder-threshold' ) ) );
|
1359 |
+
$api->notify_expiring_listings( $threshold, $now );
|
1360 |
+
}
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
|
1364 |
+
/*
|
1365 |
+
* Comments reCAPTCHA.
|
1366 |
+
*/
|
1367 |
+
|
1368 |
+
public function recaptcha_in_comments( $comment_field ) {
|
1369 |
+
$html = '';
|
1370 |
+
$html .= $comment_field;
|
1371 |
+
|
1372 |
+
// If this is not a BD page, ignore reCAPTCHA.
|
1373 |
+
if ( ! $this->controller->get_current_action() )
|
1374 |
+
return $html;
|
1375 |
+
|
1376 |
+
if ( wpbdp_get_option( 'recaptcha-on' ) && wpbdp_get_option( 'show-contact-form' ) ) {
|
1377 |
+
// Only one reCAPTCHA is allowed per page, so we work around this limitation by sharing the one in the contact form.
|
1378 |
+
add_action( 'wp_footer', array( &$this, 'comment_recaptcha_workaround' ) );
|
1379 |
+
|
1380 |
+
$html .= '<div id="wpbdp-comment-recaptcha">';
|
1381 |
+
} else {
|
1382 |
+
$html .= '<div id="wpbdp-comment-recaptcha">';
|
1383 |
+
$html .= wpbdp_recaptcha();
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
$error = '';
|
1387 |
+
if ( isset( $_GET['wpbdp-recaptcha-error'] ) && $_GET['wpbdp-recaptcha-error'] ) {
|
1388 |
+
$error = _x( "The reCAPTCHA wasn't entered correctly.", 'comment-form', 'WPBDM' );
|
1389 |
+
|
1390 |
+
add_action( 'wp_footer', array( &$this, 'restore_comment_fields' ) );
|
1391 |
+
}
|
1392 |
+
|
1393 |
+
$html .= '</div>';
|
1394 |
+
|
1395 |
+
if ( $error )
|
1396 |
+
$html .= sprintf( '<p class="wpbdp-recaptcha-error">%s</p>', $error );
|
1397 |
+
|
1398 |
+
return $html;
|
1399 |
+
}
|
1400 |
+
|
1401 |
+
public function check_comment_recaptcha( $comment_data ) {
|
1402 |
+
if ( ! wpbdp_get_option( 'recaptcha-for-comments' ) )
|
1403 |
+
return $comment_data;
|
1404 |
+
|
1405 |
+
if ( ! wpbdp_recaptcha_check_answer( $this->_comment_recaptcha_error ) ) {
|
1406 |
+
add_filter( 'pre_comment_approved', create_function( '$a', 'return \'spam\';' ) );
|
1407 |
+
}
|
1408 |
+
|
1409 |
+
return $comment_data;
|
1410 |
+
}
|
1411 |
+
|
1412 |
+
public function comment_relative_redirect( $location, $comment ) {
|
1413 |
+
if ( !isset( $this->_comment_recaptcha_error ) || empty( $this->_comment_recaptcha_error ) )
|
1414 |
+
return $location;
|
1415 |
+
|
1416 |
+
$location = substr( $location, 0, strpos( $location, '#' ) );
|
1417 |
+
$location = add_query_arg( 'wpbdp-recaptcha-error', urlencode( base64_encode( $comment->comment_ID . '/' . $this->_comment_recaptcha_error ) ), $location );
|
1418 |
+
$location .= '#commentform';
|
1419 |
+
|
1420 |
+
return $location;
|
1421 |
+
}
|
1422 |
+
|
1423 |
+
public function restore_comment_fields() {
|
1424 |
+
if ( !isset( $_GET['wpbdp-recaptcha-error'] ) || empty( $_GET['wpbdp-recaptcha-error'] ) )
|
1425 |
+
return;
|
1426 |
+
|
1427 |
+
$error_data = explode('/', base64_decode( urldecode( $_GET['wpbdp-recaptcha-error'] ) ) );
|
1428 |
+
$comment_id = $error_data ? intval( $error_data[0] ) : 0;
|
1429 |
+
$comment = get_comment( $comment_id );
|
1430 |
+
|
1431 |
+
if ( !$comment )
|
1432 |
+
return;
|
1433 |
+
|
1434 |
+
echo <<<JS
|
1435 |
+
<script type="text/javascript">//<![CDATA[
|
1436 |
+
jQuery('#comment').val("{$comment->comment_content}");
|
1437 |
+
//]]></script>
|
1438 |
+
JS;
|
1439 |
+
}
|
1440 |
+
|
1441 |
+
public function comment_recaptcha_workaround() {
|
1442 |
+
$public_key = wpbdp_get_option( 'recaptcha-public-key' );
|
1443 |
+
|
1444 |
+
echo <<<JS
|
1445 |
+
<script type="text/javascript">//<![CDATA[
|
1446 |
+
jQuery(document).ready(function(){
|
1447 |
+
jQuery('#comment, #wpbdp-contact-form-message').focusin(function(){
|
1448 |
+
var recaptchaInUse = jQuery('#wpbdp-comment-recaptcha').children().length > 0 ? 'comment' : 'contact';
|
1449 |
+
var focusedElement = jQuery(this).attr('id') == 'comment' ? 'comment' : 'contact';
|
1450 |
+
|
1451 |
+
if ( recaptchaInUse == focusedElement )
|
1452 |
+
return;
|
1453 |
+
|
1454 |
+
var recaptchaArea = focusedElement == 'comment' ? 'wpbdp-comment-recaptcha' : 'wpbdp-contact-form-recaptcha';
|
1455 |
+
|
1456 |
+
Recaptcha.destroy();
|
1457 |
+
jQuery('#wpbdp-contact-form-recaptcha, #wpbdp-comment-recaptcha').attr('class', '').empty();
|
1458 |
+
Recaptcha.create('{$public_key}', recaptchaArea);
|
1459 |
+
});
|
1460 |
+
});
|
1461 |
+
//]]></script>
|
1462 |
+
JS;
|
1463 |
+
|
1464 |
+
if ( isset( $_GET['wpbdp-recaptcha-error'] ) && !empty( $_GET['wpbdp-recaptcha-error'] ) ) {
|
1465 |
+
echo <<<JS
|
1466 |
+
<script type="text/javascript">//<![CDATA[
|
1467 |
+
jQuery(document).ready(function(){
|
1468 |
+
jQuery('#comment').focus();
|
1469 |
+
});
|
1470 |
+
//]]></script>
|
1471 |
+
JS;
|
1472 |
+
}
|
1473 |
+
}
|
1474 |
+
|
1475 |
+
// {{ Sorting options.
|
1476 |
+
public function sortbar_sort_options( $options ) {
|
1477 |
+
if ( ! wpbdp_get_option( 'listings-sortbar-enabled' ) )
|
1478 |
+
return $options;
|
1479 |
+
|
1480 |
+
$sortbar_fields = $this->settings->sortbar_fields_cb();
|
1481 |
+
$sortbar = wpbdp_get_option( 'listings-sortbar-fields' );
|
1482 |
+
|
1483 |
+
foreach ( $sortbar as $field_id ) {
|
1484 |
+
if ( ! array_key_exists( $field_id, $sortbar_fields ) )
|
1485 |
+
continue;
|
1486 |
+
$options[ 'field-' . $field_id ] = array( $sortbar_fields[ $field_id ], '', 'ASC' );
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
return $options;
|
1490 |
+
}
|
1491 |
+
|
1492 |
+
public function sortbar_query_fields( $fields ) {
|
1493 |
+
global $wpdb;
|
1494 |
+
|
1495 |
+
$sort = wpbdp_get_current_sort_option();
|
1496 |
+
|
1497 |
+
if ( ! $sort || ! in_array( str_replace( 'field-', '', $sort->option ), wpbdp_get_option( 'listings-sortbar-fields' ) ) )
|
1498 |
+
return $fields;
|
1499 |
+
|
1500 |
+
$sname = str_replace( 'field-', '', $sort->option );
|
1501 |
+
$q = '';
|
1502 |
+
|
1503 |
+
switch ( $sname ) {
|
1504 |
+
case 'user_login':
|
1505 |
+
$q = "(SELECT user_login FROM {$wpdb->users} WHERE {$wpdb->users}.ID = {$wpdb->posts}.post_author) AS user_login";
|
1506 |
+
break;
|
1507 |
+
case 'user_registered':
|
1508 |
+
$q = "(SELECT user_registered FROM {$wpdb->users} WHERE {$wpdb->users}.ID = {$wpdb->posts}.post_author) AS user_registered";
|
1509 |
+
break;
|
1510 |
+
case 'date':
|
1511 |
+
case 'modified':
|
1512 |
+
break;
|
1513 |
+
default:
|
1514 |
+
$field = wpbdp_get_form_field( $sname );
|
1515 |
+
|
1516 |
+
if ( ! $field || 'meta' != $field->get_association() )
|
1517 |
+
break;
|
1518 |
+
|
1519 |
+
$q = $wpdb->prepare( "(SELECT {$wpdb->postmeta}.meta_value FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID AND {$wpdb->postmeta}.meta_key = %s) AS field_{$sname}", '_wpbdp[fields][' . $field->get_id() . ']' );
|
1520 |
+
break;
|
1521 |
+
}
|
1522 |
+
|
1523 |
+
if ( $q )
|
1524 |
+
return $fields . ', ' . $q;
|
1525 |
+
else
|
1526 |
+
return $fields;
|
1527 |
+
}
|
1528 |
+
|
1529 |
+
public function sortbar_orderby( $orderby ) {
|
1530 |
+
global $wpdb;
|
1531 |
+
|
1532 |
+
$sort = wpbdp_get_current_sort_option();
|
1533 |
+
|
1534 |
+
if ( ! $sort || ! in_array( str_replace( 'field-', '', $sort->option ), wpbdp_get_option( 'listings-sortbar-fields' ) ) )
|
1535 |
+
return $orderby;
|
1536 |
+
|
1537 |
+
$sname = str_replace( 'field-', '', $sort->option );
|
1538 |
+
$qn = '';
|
1539 |
+
|
1540 |
+
switch ( $sname ) {
|
1541 |
+
case 'user_login':
|
1542 |
+
case 'user_registered':
|
1543 |
+
$qn = $sname;
|
1544 |
+
break;
|
1545 |
+
case 'date':
|
1546 |
+
case 'modified':
|
1547 |
+
$qn = "{$wpdb->posts}.post_{$sname}";
|
1548 |
+
break;
|
1549 |
+
default:
|
1550 |
+
$field = wpbdp_get_form_field( $sname );
|
1551 |
+
|
1552 |
+
if ( ! $field )
|
1553 |
+
break;
|
1554 |
+
|
1555 |
+
switch ( $field->get_association() ) {
|
1556 |
+
case 'title':
|
1557 |
+
case 'excerpt':
|
1558 |
+
case 'content':
|
1559 |
+
$qn = "{$wpdb->posts}.post_" . $field->get_association();
|
1560 |
+
break;
|
1561 |
+
case 'meta':
|
1562 |
+
$qn = "field_{$sname}";
|
1563 |
+
break;
|
1564 |
+
}
|
1565 |
+
|
1566 |
+
break;
|
1567 |
+
}
|
1568 |
+
|
1569 |
+
if ( $qn )
|
1570 |
+
return $orderby . ', ' . $qn . ' ' . $sort->order;
|
1571 |
+
else
|
1572 |
+
return $orderby;
|
1573 |
+
}
|
1574 |
+
// }}
|
1575 |
+
}
|
1576 |
+
|
1577 |
+
$wpbdp = new WPBDP_Plugin();
|
1578 |
+
|
core/api.php
ADDED
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Plugin API
|
4 |
+
*/
|
5 |
+
|
6 |
+
function wpbdp() {
|
7 |
+
global $wpbdp;
|
8 |
+
return $wpbdp;
|
9 |
+
}
|
10 |
+
|
11 |
+
function wpbdp_get_version() {
|
12 |
+
return WPBDP_VERSION;
|
13 |
+
}
|
14 |
+
|
15 |
+
function wpbdp_get_page_id($name='main', $unique=true) {
|
16 |
+
global $wpdb;
|
17 |
+
|
18 |
+
static $shortcodes = array(
|
19 |
+
'main' => array('businessdirectory', 'business-directory', 'WPBUSDIRMANUI'),
|
20 |
+
'add-listing' => array('businessdirectory-submitlisting', 'WPBUSDIRMANADDLISTING'),
|
21 |
+
'manage-listings' => array('businessdirectory-managelistings', 'WPBUSDIRMANMANAGELISTING'),
|
22 |
+
'view-listings' => array('businessdirectory-viewlistings', 'businessdirectory-listings', 'WPBUSDIRMANMVIEWLISTINGS'),
|
23 |
+
'paypal' => 'WPBUSDIRMANPAYPAL',
|
24 |
+
'2checkout' => 'WPBUSDIRMANTWOCHECKOUT',
|
25 |
+
'googlecheckout' => 'WPBUSDIRMANGOOGLECHECKOUT'
|
26 |
+
);
|
27 |
+
|
28 |
+
if (!array_key_exists($name, $shortcodes))
|
29 |
+
return null;
|
30 |
+
|
31 |
+
$where = '1=0';
|
32 |
+
$options = is_string($shortcodes[$name]) ? array($shortcodes[$name]) : $shortcodes[$name];
|
33 |
+
foreach ($options as $shortcode) {
|
34 |
+
$where .= sprintf(" OR post_content LIKE '%%[%s]%%'", $shortcode);
|
35 |
+
}
|
36 |
+
|
37 |
+
$page_ids = wp_cache_get( $name, 'wpbdp pages' );
|
38 |
+
|
39 |
+
if ( ! $page_ids ) {
|
40 |
+
$query = "SELECT ID FROM {$wpdb->posts} WHERE ({$where}) AND post_status = 'publish' AND post_type = 'page' ORDER BY ID";
|
41 |
+
$page_ids = $wpdb->get_col( $query );
|
42 |
+
wp_cache_set( $name, $page_ids, 'wpbdp pages' );
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( ! $page_ids )
|
46 |
+
return false;
|
47 |
+
|
48 |
+
if ( ! is_array( $page_ids ) )
|
49 |
+
$page_ids = array( $page_ids );
|
50 |
+
|
51 |
+
return $unique ? apply_filters( 'wpbdp_get_page_id', $page_ids[0], $name ) : $page_ids;
|
52 |
+
}
|
53 |
+
|
54 |
+
function wpbdp_get_page_link($name='main', $arg0=null) {
|
55 |
+
$page_id = wpbdp_get_page_id( $name );
|
56 |
+
|
57 |
+
if ( $page_id ) {
|
58 |
+
$link = _get_page_link( $page_id );
|
59 |
+
} else {
|
60 |
+
switch ( $name ) {
|
61 |
+
case 'view':
|
62 |
+
case 'viewlisting':
|
63 |
+
case 'show-listing':
|
64 |
+
case 'showlisting':
|
65 |
+
$link = get_permalink( intval( $arg0 ) );
|
66 |
+
break;
|
67 |
+
case 'edit':
|
68 |
+
case 'editlisting':
|
69 |
+
case 'edit-listing':
|
70 |
+
case 'delete':
|
71 |
+
case 'deletelisting':
|
72 |
+
case 'delete-listing':
|
73 |
+
case 'upgrade':
|
74 |
+
case 'upgradetostickylisting':
|
75 |
+
case 'upgradelisting':
|
76 |
+
case 'upgrade-listing':
|
77 |
+
$link = add_query_arg( array( 'action' => $name, 'listing_id' => intval( $arg0 ) ), wpbdp_get_page_link( 'main' ) );
|
78 |
+
break;
|
79 |
+
case 'viewlistings':
|
80 |
+
case 'view-listings':
|
81 |
+
$link = add_query_arg( array( 'action' => 'viewlistings' ), wpbdp_get_page_link( 'main' ) );
|
82 |
+
break;
|
83 |
+
case 'add':
|
84 |
+
case 'addlisting':
|
85 |
+
case 'add-listing':
|
86 |
+
case 'submit':
|
87 |
+
case 'submitlisting':
|
88 |
+
case 'submit-listing':
|
89 |
+
$link = add_query_arg( array( 'action' => 'submitlisting' ), wpbdp_get_page_link( 'main' ) );
|
90 |
+
break;
|
91 |
+
case 'search':
|
92 |
+
$link = add_query_arg( array( 'action' => 'search' ), wpbdp_get_page_link( 'main' ) );
|
93 |
+
break;
|
94 |
+
default:
|
95 |
+
if ( !wpbdp_get_page_id( 'main' ) )
|
96 |
+
return '';
|
97 |
+
|
98 |
+
$link = wpbdp_get_page_link( 'main' );
|
99 |
+
break;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
return apply_filters( 'wpbdp_get_page_link', $link, $name, $arg0 );
|
104 |
+
}
|
105 |
+
|
106 |
+
/* Admin API */
|
107 |
+
function wpbdp_admin() {
|
108 |
+
return wpbdp()->admin;
|
109 |
+
}
|
110 |
+
|
111 |
+
function wpbdp_admin_notices() {
|
112 |
+
global $wpbdp;
|
113 |
+
return $wpbdp->admin->admin_notices();
|
114 |
+
}
|
115 |
+
|
116 |
+
/* Settings API */
|
117 |
+
function wpbdp_settings_api() {
|
118 |
+
global $wpbdp;
|
119 |
+
return $wpbdp->settings;
|
120 |
+
}
|
121 |
+
|
122 |
+
function wpbdp_get_option($key, $def=null) {
|
123 |
+
global $wpbdp;
|
124 |
+
return $wpbdp->settings->get($key, $def);
|
125 |
+
}
|
126 |
+
|
127 |
+
function wpbdp_set_option($key, $value) {
|
128 |
+
global $wpbdp;
|
129 |
+
return $wpbdp->settings->set($key, $value);
|
130 |
+
}
|
131 |
+
|
132 |
+
/* Form Fields API */
|
133 |
+
function wpbdp_formfields_api() {
|
134 |
+
global $wpbdp;
|
135 |
+
return $wpbdp->formfields;
|
136 |
+
}
|
137 |
+
|
138 |
+
function wpbdp_get_formfield($id) {
|
139 |
+
if (is_numeric($id) && is_string($id))
|
140 |
+
return wpbdp_get_formfield(intval($id));
|
141 |
+
|
142 |
+
if (is_string($id))
|
143 |
+
return wpbdp_formfields_api()->getFieldsByAssociation($id, true);
|
144 |
+
|
145 |
+
return wpbdp_formfields_api()->get_field($id);
|
146 |
+
}
|
147 |
+
|
148 |
+
/* Fees/Payment API */
|
149 |
+
function wpbdp_payments_possible() {
|
150 |
+
return wpbdp_payments_api()->payments_possible();
|
151 |
+
}
|
152 |
+
|
153 |
+
function wpbdp_fees_api() {
|
154 |
+
return wpbdp()->fees;
|
155 |
+
}
|
156 |
+
|
157 |
+
function wpbdp_payments_api() {
|
158 |
+
return wpbdp()->payments;
|
159 |
+
}
|
160 |
+
|
161 |
+
/* Listings API */
|
162 |
+
function wpbdp_listings_api() {
|
163 |
+
return wpbdp()->listings;
|
164 |
+
}
|
165 |
+
|
166 |
+
function wpbdp_listing_upgrades_api() {
|
167 |
+
return wpbdp()->listings->upgrades;
|
168 |
+
}
|
169 |
+
|
170 |
+
/* Misc. */
|
171 |
+
function wpbdp_categories_list($parent=0, $hierarchical=true) {
|
172 |
+
$terms = get_categories(array(
|
173 |
+
'taxonomy' => WPBDP_CATEGORY_TAX,
|
174 |
+
'parent' => $parent,
|
175 |
+
'orderby' => 'name',
|
176 |
+
'hide_empty' => 0,
|
177 |
+
'hierarchical' => 0
|
178 |
+
));
|
179 |
+
|
180 |
+
if ($hierarchical) {
|
181 |
+
foreach ($terms as &$term) {
|
182 |
+
$term->subcategories = wpbdp_categories_list($term->term_id, true);
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
return $terms;
|
187 |
+
}
|
188 |
+
|
189 |
+
function wpbdp_get_parent_categories($catid) {
|
190 |
+
$category = get_term(intval($catid), WPBDP_CATEGORY_TAX);
|
191 |
+
|
192 |
+
if ($category->parent) {
|
193 |
+
return array_merge(array($category), wpbdp_get_parent_categories($category->parent));
|
194 |
+
}
|
195 |
+
|
196 |
+
return array($category);
|
197 |
+
}
|
198 |
+
|
199 |
+
function wpbdp_get_parent_catids($catid) {
|
200 |
+
$parent_categories = wpbdp_get_parent_categories($catid);
|
201 |
+
array_walk($parent_categories, create_function('&$x', '$x = intval($x->term_id);'));
|
202 |
+
|
203 |
+
return $parent_categories;
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Checks if permalinks are enabled.
|
208 |
+
* @return boolean
|
209 |
+
* @since 2.1
|
210 |
+
*/
|
211 |
+
function wpbdp_rewrite_on() {
|
212 |
+
global $wp_rewrite;
|
213 |
+
return $wp_rewrite->permalink_structure ? true : false;
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Checks if a given user can perform some action to a listing.
|
218 |
+
* @param string $action the action to be checked. available actions are 'view', 'edit', 'delete' and 'upgrade-to-sticky'
|
219 |
+
* @param (object|int) $listing_id the listing ID. if null, the current post ID will be used
|
220 |
+
* @param int $user_id the user ID. if null, the current user will be used
|
221 |
+
* @return boolean
|
222 |
+
* @since 2.1
|
223 |
+
*/
|
224 |
+
function wpbdp_user_can($action, $listing_id=null, $user_id=null) {
|
225 |
+
$listing_id = $listing_id ? ( is_object($listing_id) ? $listing_id->ID : intval($listing_id) ) : get_the_ID();
|
226 |
+
$user_id = $user_id ? $user_id : wp_get_current_user()->ID;
|
227 |
+
$post = get_post($listing_id);
|
228 |
+
|
229 |
+
if ($post->post_type != WPBDP_POST_TYPE)
|
230 |
+
return false;
|
231 |
+
|
232 |
+
if ( isset($_GET['preview']) )
|
233 |
+
return false;
|
234 |
+
|
235 |
+
switch ($action) {
|
236 |
+
case 'view':
|
237 |
+
return true;
|
238 |
+
break;
|
239 |
+
case 'edit':
|
240 |
+
case 'delete':
|
241 |
+
return user_can($user_id, 'administrator') || ( $post->post_author && $post->post_author == $user_id );
|
242 |
+
break;
|
243 |
+
case 'upgrade-to-sticky':
|
244 |
+
if ( !wpbdp_get_option('featured-on') || !wpbdp_get_option('payments-on') )
|
245 |
+
return false;
|
246 |
+
|
247 |
+
if ( !wpbdp_payments_possible() )
|
248 |
+
return false;
|
249 |
+
|
250 |
+
$sticky_info = wpbdp_listing_upgrades_api()->get_info( $listing_id );
|
251 |
+
return $sticky_info->upgradeable && (user_can($user_id, 'administrator') || ($post->post_author == $user_id));
|
252 |
+
break;
|
253 |
+
}
|
254 |
+
|
255 |
+
return false;
|
256 |
+
}
|
257 |
+
|
258 |
+
function wpbdp_get_post_by_slug($slug, $post_type=null) {
|
259 |
+
$post_type = $post_type ? $post_type : WPBDP_POST_TYPE;
|
260 |
+
|
261 |
+
$posts = get_posts(array(
|
262 |
+
'name' => $slug,
|
263 |
+
'post_type' => $post_type,
|
264 |
+
'post_status' => 'publish',
|
265 |
+
'numberposts' => 1
|
266 |
+
));
|
267 |
+
|
268 |
+
if ($posts)
|
269 |
+
return $posts[0];
|
270 |
+
else
|
271 |
+
return 0;
|
272 |
+
}
|
273 |
+
|
274 |
+
function wpbdp_get_current_sort_option() {
|
275 |
+
if ($sort = trim(wpbdp_getv($_GET, 'wpbdp_sort', null))) {
|
276 |
+
$order = substr($sort, 0, 1) == '-' ? 'DESC' : 'ASC';
|
277 |
+
$sort = ltrim($sort, '-');
|
278 |
+
|
279 |
+
$obj = new StdClass();
|
280 |
+
$obj->option = $sort;
|
281 |
+
$obj->order = $order;
|
282 |
+
|
283 |
+
return $obj;
|
284 |
+
}
|
285 |
+
|
286 |
+
return null;
|
287 |
+
}
|
288 |
+
|
289 |
+
/*
|
290 |
+
* @since 2.1.6
|
291 |
+
*/
|
292 |
+
function _wpbdp_resize_image_if_needed($id) {
|
293 |
+
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
294 |
+
|
295 |
+
if ( $metadata = wp_get_attachment_metadata( $id ) ) {
|
296 |
+
if ( !isset( $metadata['sizes']['wpbdp-thumb'] ) || !isset( $metadata['sizes']['wpbdp-thumb'] ) ||
|
297 |
+
(isset($metadata['sizes']['wpbdp-thumb']) && (abs( intval($metadata['sizes']['wpbdp-thumb']['width']) - intval( wpbdp_get_option( 'thumbnail-width' ) ) ) >= 15) ) ) {
|
298 |
+
wpbdp_log( sprintf( 'Re-creating thumbnails for attachment %d', $id ) );
|
299 |
+
$filename = get_attached_file($id, true);
|
300 |
+
$attach_data = wp_generate_attachment_metadata( $id, $filename );
|
301 |
+
wp_update_attachment_metadata( $id, $attach_data );
|
302 |
+
}
|
303 |
+
}
|
304 |
+
}
|
305 |
+
|
306 |
+
/*
|
307 |
+
* @since 2.1.7
|
308 |
+
*/
|
309 |
+
function wpbdp_format_currency($amount, $decimals = 2, $currency = null) {
|
310 |
+
if ( $amount == 0.0 )
|
311 |
+
return '—';
|
312 |
+
|
313 |
+
return ( ! $currency ? wpbdp_get_option( 'currency-symbol' ) : $currency ) . ' ' . number_format( $amount, $decimals );
|
314 |
+
}
|
315 |
+
|
316 |
+
|
317 |
+
/**
|
318 |
+
* @since 2.3
|
319 |
+
*/
|
320 |
+
function wpbdp_has_module( $module ) {
|
321 |
+
global $wpbdp;
|
322 |
+
return $wpbdp->has_module( $module );
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* @since 3.5.3
|
327 |
+
*/
|
328 |
+
function wpbdp_get_post_by_id_or_slug( $id_or_slug = false, $try_first = 'id', $result = 'post' ) {
|
329 |
+
if ( 'slug' == $try_first )
|
330 |
+
$strategies = array( 'slug', 'id' );
|
331 |
+
else
|
332 |
+
$strategies = is_numeric( $id_or_slug ) ? array( 'id', 'slug' ) : array( 'slug' );
|
333 |
+
|
334 |
+
global $wpdb;
|
335 |
+
$listing_id = 0;
|
336 |
+
|
337 |
+
foreach ( $strategies as $s ) {
|
338 |
+
switch ( $s ) {
|
339 |
+
case 'id':
|
340 |
+
$listing_id = intval( $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE ID = %d AND post_type = %s", $id_or_slug, WPBDP_POST_TYPE ) ) );
|
341 |
+
break;
|
342 |
+
case 'slug':
|
343 |
+
$listing_id = intval( $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", $id_or_slug, WPBDP_POST_TYPE ) ) );
|
344 |
+
break;
|
345 |
+
}
|
346 |
+
|
347 |
+
if ( $listing_id )
|
348 |
+
break;
|
349 |
+
}
|
350 |
+
|
351 |
+
if ( ! $listing_id )
|
352 |
+
return null;
|
353 |
+
|
354 |
+
if ( 'id' == $result )
|
355 |
+
return $listing_id;
|
356 |
+
|
357 |
+
return get_post( $listing_id );
|
358 |
+
}
|
359 |
+
|
core/class-ajax-response.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_AJAX_Response {
|
4 |
+
public $success = true;
|
5 |
+
public $error = '';
|
6 |
+
public $message = '';
|
7 |
+
public $data = array();
|
8 |
+
|
9 |
+
public function add( $k, $v ) {
|
10 |
+
$this->data[ $k ] = $v;
|
11 |
+
}
|
12 |
+
|
13 |
+
public function set_message( $s ) {
|
14 |
+
$this->message = $s;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function send_error( $error = null ) {
|
18 |
+
if ( $error )
|
19 |
+
$this->error = $error;
|
20 |
+
|
21 |
+
$this->success = false;
|
22 |
+
$this->message = '';
|
23 |
+
$this->data = null;
|
24 |
+
|
25 |
+
$this->send();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function send() {
|
29 |
+
$response = array();
|
30 |
+
$response['success'] = $this->success;
|
31 |
+
|
32 |
+
if ( ! $this->success ) {
|
33 |
+
$response['error'] = $this->error ? $this->error : 'Unknown error';
|
34 |
+
} else {
|
35 |
+
$response['data'] = $this->data;
|
36 |
+
$response['message'] = $this->message;
|
37 |
+
}
|
38 |
+
|
39 |
+
print json_encode( $response );
|
40 |
+
die();
|
41 |
+
}
|
42 |
+
}
|
core/class-db-model.php
ADDED
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
abstract class WPBDP_DB_Model {
|
3 |
+
|
4 |
+
protected $id = null;
|
5 |
+
|
6 |
+
public function set( $data = array() ) {
|
7 |
+
throw new Exception( 'Not implemented yet!' );
|
8 |
+
}
|
9 |
+
|
10 |
+
abstract public function save();
|
11 |
+
abstract public function delete();
|
12 |
+
|
13 |
+
public function validates() {
|
14 |
+
return true;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_id() {
|
18 |
+
return $this->id;
|
19 |
+
}
|
20 |
+
|
21 |
+
protected function fill_from_data( &$data = array(), $defaults = array() ) {
|
22 |
+
$data = (array) $data;
|
23 |
+
$keys = array_unique( array_merge( array_keys( $data ), array_keys( $defaults ) ) );
|
24 |
+
|
25 |
+
foreach ( $keys as $k ) {
|
26 |
+
$v = isset( $data[ $k ] ) ? maybe_unserialize( $data[ $k ] ) : null;
|
27 |
+
|
28 |
+
if ( $v )
|
29 |
+
$this->{$k} = $v;
|
30 |
+
elseif( isset( $defaults [ $k ] ) )
|
31 |
+
$this->{$k} = $defaults[ $k ];
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Convenience method to obtain a record from the database by ID.
|
37 |
+
* Subclasses should override this method because we have to support PHP 5.2 where late static binding is not available.
|
38 |
+
* @param int $id The row ID.
|
39 |
+
* @return object
|
40 |
+
*/
|
41 |
+
public static function get( $id ) {
|
42 |
+
throw new Exception('get() method not implemented.');
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Convenience method to search records in a database table.
|
47 |
+
* Subclasses should override this method because we have to support PHP 5.2 where late static binding is not available.
|
48 |
+
* @return array
|
49 |
+
*/
|
50 |
+
public static function find( $args = array(), $lightweight = false ) {
|
51 |
+
throw new Exception('find() method not implemented.');
|
52 |
+
}
|
53 |
+
|
54 |
+
protected static function _find( $args = array(), $lightweight = false, $table, $classname = '' ) {
|
55 |
+
if ( ! $table || ! $classname || ! class_exists( $classname ) )
|
56 |
+
throw new Exception( 'Please provide a table and class name.' );
|
57 |
+
|
58 |
+
global $wpdb;
|
59 |
+
|
60 |
+
$query = "SELECT * FROM {$table} WHERE 1=1";
|
61 |
+
$single = isset( $args['_single'] ) && true == $args['_single'];
|
62 |
+
$order = isset( $args['_order'] ) && !empty( $args['_order'] ) ? trim( $args['_order'] ) : null;
|
63 |
+
$limit = isset( $args['_limit'] ) && !empty( $args['_limit'] ) ? intval( $args['_limit'] ) : null;
|
64 |
+
|
65 |
+
foreach ( $args as $arg => $value ) {
|
66 |
+
if ( is_null( $value ) || in_array( $arg, array( '_single', '_order', '_limit' ), true ) )
|
67 |
+
continue;
|
68 |
+
|
69 |
+
$query .= $wpdb->prepare( " AND {$arg}=" . ( is_int( $value ) ? '%d' : '%s' ), $value );
|
70 |
+
}
|
71 |
+
|
72 |
+
if ( $single )
|
73 |
+
$limit = 1;
|
74 |
+
|
75 |
+
if ( $order ) {
|
76 |
+
$order_field = wpbdp_starts_with( $order, '-' ) ? substr( $order, 1 ) : $order;
|
77 |
+
$order_dir = wpbdp_starts_with( $order, '-' ) ? 'DESC' : 'ASC';
|
78 |
+
|
79 |
+
$query .= " ORDER BY {$order_field} {$order_dir}";
|
80 |
+
}
|
81 |
+
|
82 |
+
if ( $limit > 0 )
|
83 |
+
$query .= " LIMIT {$limit}";
|
84 |
+
|
85 |
+
$results = $wpdb->get_results( $query, ARRAY_A );
|
86 |
+
|
87 |
+
if ( ! $lightweight ) {
|
88 |
+
foreach ( $results as &$r ) {
|
89 |
+
$r = new $classname( $r );
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
return $single ? ( $results ? $results[0] : null ) : $results;
|
94 |
+
}
|
95 |
+
|
96 |
+
protected static function _get( $id, $table, $classname = '' ) {
|
97 |
+
return self::_find( array( 'id' => $id, '_single' => true ), false, $table, $classname );
|
98 |
+
}
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
// TODO: it'd be nice if DB_Model knew about the underlying table structure. Maybe save it inside a class var.
|
103 |
+
// That way we could handle created_at/updated_at without querying the database two times and also be more clever
|
104 |
+
// about saving files depending on the coljumn type or automatically convert DECIMALs to floats, etc.
|
105 |
+
class WPBDP_DB_Model2 {
|
106 |
+
|
107 |
+
public $errors = array();
|
108 |
+
|
109 |
+
protected $table = '';
|
110 |
+
protected $serialized = array();
|
111 |
+
|
112 |
+
private $attrs = array();
|
113 |
+
|
114 |
+
|
115 |
+
public function __construct( $data = array() ) {
|
116 |
+
$this->fill( $data );
|
117 |
+
}
|
118 |
+
|
119 |
+
public function fill( $data = array() ) {
|
120 |
+
foreach ( $data as $k => $v ) {
|
121 |
+
$this->attrs[ $k ] = ( in_array( $k, $this->serialized, true) && $v ) ? maybe_unserialize( $v ) : $v;
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
private function validate() {
|
126 |
+
$this->errors = $this->_validate();
|
127 |
+
return empty( $this->errors ) ? true : false;
|
128 |
+
}
|
129 |
+
|
130 |
+
public function sanitize() {
|
131 |
+
}
|
132 |
+
|
133 |
+
protected function _validate() {
|
134 |
+
return array();
|
135 |
+
}
|
136 |
+
|
137 |
+
public function is_valid() {
|
138 |
+
return $this->validate();
|
139 |
+
}
|
140 |
+
|
141 |
+
public function is_invalid() {
|
142 |
+
return ! $this->is_valid();
|
143 |
+
}
|
144 |
+
|
145 |
+
protected function update_timestamps( $row ) {
|
146 |
+
global $wpdb;
|
147 |
+
$table = $wpdb->prefix . 'wpbdp_' . $this->table;
|
148 |
+
|
149 |
+
if ( isset( $this->attrs['id'] ) && $this->attrs['id'] ) {
|
150 |
+
} else {
|
151 |
+
if ( ! isset( $row['created_at'] ) && $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$table} LIKE %s", 'created_at' ) ) ) {
|
152 |
+
$row['created_at'] = current_time( 'mysql' );
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
if ( $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$table} LIKE %s", 'updated_at' ) ) ) {
|
157 |
+
$row['updated_at'] = current_time( 'mysql' );
|
158 |
+
}
|
159 |
+
|
160 |
+
return $row;
|
161 |
+
}
|
162 |
+
|
163 |
+
public function save( $validate = true ) {
|
164 |
+
global $wpdb;
|
165 |
+
|
166 |
+
if ( $validate )
|
167 |
+
$this->sanitize();
|
168 |
+
|
169 |
+
if ( isset( $this->attrs['id'] ) && $this->attrs['id'] )
|
170 |
+
return $this->update( $validate );
|
171 |
+
else
|
172 |
+
return $this->insert( $validate );
|
173 |
+
}
|
174 |
+
|
175 |
+
public function delete() {
|
176 |
+
if ( ! isset( $this->attrs['id'] ) || ! $this->attrs['id'] )
|
177 |
+
return false;
|
178 |
+
|
179 |
+
global $wpdb;
|
180 |
+
$table = $wpdb->prefix . 'wpbdp_' . $this->table;
|
181 |
+
return ( false !== $wpdb->delete( $table, array( 'id' => $this->attrs['id'] ) ) );
|
182 |
+
}
|
183 |
+
|
184 |
+
private function insert( $validate = true ) {
|
185 |
+
global $wpdb;
|
186 |
+
$table = $wpdb->prefix . 'wpbdp_' . $this->table;
|
187 |
+
|
188 |
+
if ( $validate && ! $this->validate() )
|
189 |
+
return false;
|
190 |
+
|
191 |
+
$row = array();
|
192 |
+
foreach ( $this->attrs as $k => $v ) {
|
193 |
+
if ( ! is_null( $v ) )
|
194 |
+
$row[ $k ] = in_array( $k, $this->serialized, true ) ? ( $v ? serialize( $v ) : '' ): $v;
|
195 |
+
}
|
196 |
+
|
197 |
+
$row = $this->update_timestamps( $row );
|
198 |
+
|
199 |
+
if ( false !== $wpdb->insert( $table, $row ) ) {
|
200 |
+
$this->attrs['id'] = intval( $wpdb->insert_id );
|
201 |
+
return true;
|
202 |
+
}
|
203 |
+
|
204 |
+
return false;
|
205 |
+
}
|
206 |
+
|
207 |
+
private function update( $validate = true ) {
|
208 |
+
global $wpdb;
|
209 |
+
$table = $wpdb->prefix . 'wpbdp_' . $this->table;
|
210 |
+
|
211 |
+
$row = array();
|
212 |
+
foreach ( $this->attrs as $k => $v ) {
|
213 |
+
if ( ! is_null( $v ) )
|
214 |
+
$row[ $k ] = in_array( $k, $this->serialized, true ) ? ( $v ? serialize( $v ) : '' ): $v;
|
215 |
+
}
|
216 |
+
|
217 |
+
$row = $this->update_timestamps( $row );
|
218 |
+
|
219 |
+
// if ( $validate )
|
220 |
+
// $this->validate();
|
221 |
+
|
222 |
+
return false !== $wpdb->update( $table, $row, array( 'id' => $this->id ) );
|
223 |
+
}
|
224 |
+
|
225 |
+
public function &get_attr( $k ) {
|
226 |
+
if ( array_key_exists( $k, $this->attrs ) ) {
|
227 |
+
$value = $this->attrs[ $k ];
|
228 |
+
} else {
|
229 |
+
$value = null;
|
230 |
+
}
|
231 |
+
|
232 |
+
return $value;
|
233 |
+
}
|
234 |
+
|
235 |
+
public function set_attr( $k, $v ) {
|
236 |
+
$this->attrs[ $k ] = $v;
|
237 |
+
}
|
238 |
+
|
239 |
+
public function &__get( $k ) {
|
240 |
+
if ( method_exists( $this, "get_$k" ) ) {
|
241 |
+
$v = call_user_func( array( &$this, "get_$k" ) );
|
242 |
+
return $v;
|
243 |
+
}
|
244 |
+
|
245 |
+
return $this->get_attr( $k );
|
246 |
+
}
|
247 |
+
|
248 |
+
public function __set( $k, $v ) {
|
249 |
+
if ( method_exists( $this, "set_$k" ) ) {
|
250 |
+
return call_user_func( array( &$this, "set_$k" ), $v );
|
251 |
+
}
|
252 |
+
|
253 |
+
// if ( array_key_exists( $k, $this->attrs ) )
|
254 |
+
return $this->set_attr( $k, $v );
|
255 |
+
|
256 |
+
// throw new Exception( 'Undefined Property: ' . $k );
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Convenience method to search records in a database table.
|
261 |
+
* Subclasses should override this method because we have to support PHP 5.2 where late static binding is not available.
|
262 |
+
* @return array
|
263 |
+
*/
|
264 |
+
public static function find( $id, $args = array() ) {
|
265 |
+
throw new Exception('find() method not implemented.');
|
266 |
+
}
|
267 |
+
|
268 |
+
protected static function _find( $id, $args = array(), $table = '', $classname = '' ) {
|
269 |
+
if ( ! $table || ! $classname || ! class_exists( $classname ) )
|
270 |
+
throw new Exception( 'Please provide a table and class name.' );
|
271 |
+
|
272 |
+
global $wpdb;
|
273 |
+
|
274 |
+
$single = false;
|
275 |
+
|
276 |
+
switch ( $id ) {
|
277 |
+
case 'first':
|
278 |
+
$args['_limit'] = 1;
|
279 |
+
$args['_order'] = 'id';
|
280 |
+
$single = true;
|
281 |
+
|
282 |
+
break;
|
283 |
+
case 'last':
|
284 |
+
$args['_limit'] = 1;
|
285 |
+
$args['_order'] = '-id';
|
286 |
+
$single = true;
|
287 |
+
|
288 |
+
break;
|
289 |
+
case 'all':
|
290 |
+
break;
|
291 |
+
default:
|
292 |
+
$args['id'] = intval( $id );
|
293 |
+
$args['_limit'] = 1;
|
294 |
+
$single = true;
|
295 |
+
|
296 |
+
break;
|
297 |
+
}
|
298 |
+
|
299 |
+
$single = ( ! $single && isset( $args['_single'] ) && true == $args['_single'] ) ? true : $single;
|
300 |
+
$order = isset( $args['_order'] ) ? $args['_order'] : '';
|
301 |
+
$limit = isset( $args['_limit'] ) ? $args['_limit'] : '';
|
302 |
+
$extra = isset( $args['_query_extra'] ) ? $args['_query_extra'] : array();
|
303 |
+
|
304 |
+
$query = "SELECT t.*";
|
305 |
+
|
306 |
+
if ( isset( $extra['fields'] ) )
|
307 |
+
$query .= ', ' . $extra['fields'];
|
308 |
+
|
309 |
+
$query .= " FROM {$table} t";
|
310 |
+
if ( isset( $extra['table'] ) )
|
311 |
+
$query .= ', ' . $extra['table'] . ' ';
|
312 |
+
|
313 |
+
$query .= " WHERE 1=1";
|
314 |
+
if ( isset( $extra['where'] ) )
|
315 |
+
$query .= ' ' . $extra['where'] . ' ';
|
316 |
+
|
317 |
+
foreach ( $args as $arg => $value ) {
|
318 |
+
if ( is_null( $value ) || in_array( $arg, array( '_single', '_order', '_limit', '_query_extra' ), true ) )
|
319 |
+
continue;
|
320 |
+
|
321 |
+
if ( is_array( $value ) ) {
|
322 |
+
$value_str = implode( ',', $value );
|
323 |
+
$query .= " AND t.{$arg} IN ({$value_str})";
|
324 |
+
} elseif ( $value[0] == '>' ) {
|
325 |
+
$query .= " AND t.{$arg} {$value}";
|
326 |
+
} else {
|
327 |
+
$query .= $wpdb->prepare( " AND t.{$arg}=" . ( is_int( $value ) ? '%d' : '%s' ), $value );
|
328 |
+
}
|
329 |
+
}
|
330 |
+
|
331 |
+
if ( isset( $extra['groupby'] ) )
|
332 |
+
$query .= ' GROUP BY ' . $extra['groupby'];
|
333 |
+
|
334 |
+
if ( $order ) {
|
335 |
+
$order_field = wpbdp_starts_with( $order, '-' ) ? substr( $order, 1 ) : $order;
|
336 |
+
$order_dir = wpbdp_starts_with( $order, '-' ) ? 'DESC' : 'ASC';
|
337 |
+
|
338 |
+
if ( isset( $extra['orderby'] ) )
|
339 |
+
$query .= ' ORDER BY ' . $extra['orderby'];
|
340 |
+
else
|
341 |
+
$query .= " ORDER BY t.{$order_field} {$order_dir}";
|
342 |
+
}
|
343 |
+
|
344 |
+
if ( $limit > 0 )
|
345 |
+
$query .= " LIMIT {$limit}";
|
346 |
+
|
347 |
+
if ( $single ) {
|
348 |
+
if ( $row = $wpdb->get_row( $query, ARRAY_A ) )
|
349 |
+
return new $classname( $row );
|
350 |
+
else
|
351 |
+
return null;
|
352 |
+
}
|
353 |
+
|
354 |
+
return array_map( create_function( '$x', 'return new ' . $classname . '( $x );' ), $wpdb->get_results( $query, ARRAY_A ) );
|
355 |
+
}
|
356 |
+
|
357 |
+
}
|
core/class-email.php
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* E-mail handling class.
|
4 |
+
* @since 2.1
|
5 |
+
*/
|
6 |
+
class WPBDP_Email {
|
7 |
+
|
8 |
+
public $headers = array();
|
9 |
+
public $subject = '';
|
10 |
+
public $from = '';
|
11 |
+
public $reply_to = '';
|
12 |
+
public $to = array();
|
13 |
+
public $cc = array();
|
14 |
+
public $bcc = array();
|
15 |
+
|
16 |
+
public $body = '';
|
17 |
+
public $plain = '';
|
18 |
+
public $html = '';
|
19 |
+
|
20 |
+
|
21 |
+
public function __construct() {
|
22 |
+
}
|
23 |
+
|
24 |
+
private function prepare_html() {
|
25 |
+
if (!$this->html) {
|
26 |
+
$text = $this->body ? $this->body : $this->plain;
|
27 |
+
$text = str_ireplace(array("<br>", "<br/>", "<br />"), "\n", $text);
|
28 |
+
$this->html = nl2br($text);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
private function prepare_plain() {
|
33 |
+
if (!$this->plain) {
|
34 |
+
$text = $this->body ? $this->body : $this->html;
|
35 |
+
$this->plain = strip_tags($text); // FIXME: this removes 'valid' plain text like <whatever>
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
private function get_headers() {
|
40 |
+
$headers = array();
|
41 |
+
|
42 |
+
if ( ! isset( $this->headers['MIME-Version'] ) )
|
43 |
+
$headers['MIME-Version'] = '1.0';
|
44 |
+
|
45 |
+
if ( ! isset( $this->headers['Content-Type'] ) )
|
46 |
+
$headers['Content-Type'] = 'text/html; charset=' . get_option( 'blog_charset' );
|
47 |
+
|
48 |
+
$headers['From'] = $this->from;
|
49 |
+
|
50 |
+
if ( $this->cc )
|
51 |
+
$headers['Cc'] = implode( ',', is_array( $this->cc ) ? $this->cc : array( $this->cc ) );
|
52 |
+
|
53 |
+
if ( $this->bcc )
|
54 |
+
$headers['Bcc'] = implode( ',', is_array( $this->bcc ) ? $this->bcc : array( $this->bcc ) );
|
55 |
+
|
56 |
+
foreach ( $this->headers as $k => $v ) {
|
57 |
+
if ( in_array( $k, array( 'MIME-Version', 'Content-Type', 'From', 'Cc', 'Bcc' ) ) )
|
58 |
+
continue;
|
59 |
+
|
60 |
+
$headers[ $k ] = $v;
|
61 |
+
}
|
62 |
+
|
63 |
+
return $headers;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Sends the email.
|
68 |
+
* @param string $format allowed values are 'html', 'plain' or 'both'
|
69 |
+
* @return boolean true on success, false otherwise
|
70 |
+
*/
|
71 |
+
public function send($format='both') {
|
72 |
+
$this->subject = strip_tags( $this->subject );
|
73 |
+
|
74 |
+
// TODO: implement 'plain' and 'both'
|
75 |
+
$this->prepare_html();
|
76 |
+
$this->prepare_plain();
|
77 |
+
|
78 |
+
$this->from = $this->from ? $this->from : sprintf( '%s <%s>', get_option( 'blogname' ), get_option( 'admin_email' ) );
|
79 |
+
$to = $this->to;
|
80 |
+
|
81 |
+
if ( ! $this->to )
|
82 |
+
return false;
|
83 |
+
|
84 |
+
// Workaround a known WP bug where some headers are ignored if passed inside an array.
|
85 |
+
$headers = '';
|
86 |
+
foreach ( $this->get_headers() as $h => $v ) {
|
87 |
+
$headers .= $h . ': ' . $v . "\r\n";
|
88 |
+
}
|
89 |
+
|
90 |
+
return wp_mail( $this->to, $this->subject, $this->html, $headers );
|
91 |
+
}
|
92 |
+
|
93 |
+
}
|
94 |
+
|
core/class-form-field-type.php
ADDED
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPBDP_Form_Field_Type {
|
3 |
+
|
4 |
+
private $name = null;
|
5 |
+
|
6 |
+
public function __construct( $name = '' ) {
|
7 |
+
if ( ! $name )
|
8 |
+
$name = str_replace( array( 'WPBDP_', '_' ), array( '', ' ' ), get_class( $this ) );
|
9 |
+
|
10 |
+
$this->name = trim( $name );
|
11 |
+
}
|
12 |
+
|
13 |
+
public function get_id() {
|
14 |
+
return get_class( $this );
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_name() {
|
18 |
+
return $this->name;
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Called after a field of this type is constructed.
|
23 |
+
* @param object $field
|
24 |
+
*/
|
25 |
+
public function setup_field( &$field ) {
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* TODO: dodoc.
|
31 |
+
* @since 3.4
|
32 |
+
*/
|
33 |
+
public function get_behavior_flags( &$field ) {
|
34 |
+
return array();
|
35 |
+
}
|
36 |
+
|
37 |
+
public function get_field_value( &$field, $post_id ) {
|
38 |
+
$post = get_post( $post_id );
|
39 |
+
|
40 |
+
if ( !$post )
|
41 |
+
return null;
|
42 |
+
|
43 |
+
switch ( $field->get_association() ) {
|
44 |
+
case 'title':
|
45 |
+
$value = $post->post_title;
|
46 |
+
break;
|
47 |
+
case 'excerpt':
|
48 |
+
$value = $post->post_excerpt;
|
49 |
+
break;
|
50 |
+
case 'content':
|
51 |
+
$value = $post->post_content;
|
52 |
+
break;
|
53 |
+
case 'category':
|
54 |
+
$value = wp_get_object_terms( $post_id, WPBDP_CATEGORY_TAX, array( 'fields' => 'ids' ) );
|
55 |
+
break;
|
56 |
+
case 'tags':
|
57 |
+
$value = wp_get_object_terms( $post_id, WPBDP_TAGS_TAX, array( 'fields' => 'names' ) );
|
58 |
+
break;
|
59 |
+
case 'meta':
|
60 |
+
$value = get_post_meta( $post_id, '_wpbdp[fields][' . $field->get_id() . ']', true );
|
61 |
+
break;
|
62 |
+
default:
|
63 |
+
$value = null;
|
64 |
+
break;
|
65 |
+
}
|
66 |
+
|
67 |
+
return $value;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function get_field_html_value( &$field, $post_id ) {
|
71 |
+
$post = get_post( $post_id );
|
72 |
+
|
73 |
+
switch ( $field->get_association() ) {
|
74 |
+
case 'title':
|
75 |
+
$value = sprintf( '<a href="%s">%s</a>', get_permalink( $post_id ), get_the_title( $post_id ) );
|
76 |
+
break;
|
77 |
+
case 'excerpt':
|
78 |
+
$value = apply_filters( 'get_the_excerpt', wpautop( $post->post_excerpt, true ) );
|
79 |
+
break;
|
80 |
+
case 'content':
|
81 |
+
$value = apply_filters( 'the_content', $post->post_content );
|
82 |
+
break;
|
83 |
+
case 'category':
|
84 |
+
$value = get_the_term_list( $post_id, WPBDP_CATEGORY_TAX, '', ', ', '' );
|
85 |
+
break;
|
86 |
+
case 'tags':
|
87 |
+
$value = get_the_term_list( $post_id, WPBDP_TAGS_TAX, '', ', ', '' );
|
88 |
+
break;
|
89 |
+
case 'meta':
|
90 |
+
default:
|
91 |
+
$value = $field->value( $post_id );
|
92 |
+
break;
|
93 |
+
}
|
94 |
+
|
95 |
+
return $value;
|
96 |
+
}
|
97 |
+
|
98 |
+
public function get_field_plain_value( &$field, $post_id ) {
|
99 |
+
return $this->get_field_value( $field, $post_id );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @since 3.4.1
|
104 |
+
*/
|
105 |
+
public function get_field_csv_value( &$field, $post_id ) {
|
106 |
+
return $this->get_field_plain_value( $field, $post_id );
|
107 |
+
}
|
108 |
+
|
109 |
+
public function is_empty_value( $value ) {
|
110 |
+
return empty( $value );
|
111 |
+
}
|
112 |
+
|
113 |
+
public function convert_input( &$field, $input ) {
|
114 |
+
return $input;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* @since 3.4.1
|
119 |
+
*/
|
120 |
+
public function convert_csv_input( &$field, $input = '' ) {
|
121 |
+
return $this->convert_input( $field, $input );
|
122 |
+
}
|
123 |
+
|
124 |
+
public function store_field_value( &$field, $post_id, $value ) {
|
125 |
+
switch ( $field->get_association() ) {
|
126 |
+
case 'title':
|
127 |
+
wp_update_post( array( 'ID' => $post_id, 'post_title' => trim( strip_tags( $value ) ) ) );
|
128 |
+
break;
|
129 |
+
case 'excerpt':
|
130 |
+
wp_update_post( array( 'ID' => $post_id, 'post_excerpt' => $value ) );
|
131 |
+
break;
|
132 |
+
case 'content':
|
133 |
+
wp_update_post( array( 'ID' => $post_id, 'post_content' => $value ) );
|
134 |
+
break;
|
135 |
+
case 'category':
|
136 |
+
wp_set_post_terms( $post_id, $value, WPBDP_CATEGORY_TAX, false );
|
137 |
+
break;
|
138 |
+
case 'tags':
|
139 |
+
wp_set_post_terms( $post_id, $value, WPBDP_TAGS_TAX, false );
|
140 |
+
break;
|
141 |
+
case 'meta':
|
142 |
+
default:
|
143 |
+
update_post_meta( $post_id, '_wpbdp[fields][' . $field->get_id() . ']', $value );
|
144 |
+
break;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
// this function should not try to hide values depending on field, context or value itself.
|
149 |
+
public function display_field( &$field, $post_id, $display_context ) {
|
150 |
+
return self::standard_display_wrapper( $field, $field->html_value( $post_id ) );
|
151 |
+
}
|
152 |
+
|
153 |
+
public function render_field_inner( &$field, $value, $render_context, &$extra=null ) {
|
154 |
+
return '';
|
155 |
+
}
|
156 |
+
|
157 |
+
public function render_field( &$field, $value, $render_context, &$extra=null ) {
|
158 |
+
$html = '';
|
159 |
+
|
160 |
+
switch ( $render_context ) {
|
161 |
+
case 'search':
|
162 |
+
$html .= sprintf( '<div class="wpbdp-search-filter %s %s" %s>',
|
163 |
+
$field->get_field_type()->get_id(),
|
164 |
+
implode(' ', $field->css_classes ),
|
165 |
+
$this->html_attributes( $field->html_attributes ) );
|
166 |
+
$html .= sprintf( '<div class="label"><label>%s</label></div>', esc_html( apply_filters( 'wpbdp_render_field_label', $field->get_label(), $field ) ) );
|
167 |
+
$html .= '<div class="field inner">';
|
168 |
+
|
169 |
+
$field_inner = $this->render_field_inner( $field, $value, $render_context, $extra );
|
170 |
+
$field_inner = apply_filters_ref_array( 'wpbdp_render_field_inner', array( $field_inner, &$field, $value, $render_context, &$extra ) );
|
171 |
+
|
172 |
+
$html .= $field_inner;
|
173 |
+
$html .= '</div>';
|
174 |
+
$html .= '</div>';
|
175 |
+
|
176 |
+
break;
|
177 |
+
|
178 |
+
case 'submit':
|
179 |
+
case 'edit':
|
180 |
+
default:
|
181 |
+
$html_attributes = $this->html_attributes( apply_filters_ref_array( 'wpbdp_render_field_html_attributes', array( $field->html_attributes, &$field, $value, $render_context, &$extra ) ) );
|
182 |
+
|
183 |
+
$html .= sprintf( '<div class="%s" %s>',
|
184 |
+
implode( ' ', $field->get_css_classes( $render_context ) ),
|
185 |
+
$html_attributes );
|
186 |
+
$html .= '<div class="wpbdp-form-field-label">';
|
187 |
+
$html .= sprintf( '<label for="%s">%s</label>', 'wpbdp-field-' . $field->get_id(), apply_filters( 'wpbdp_render_field_label', $field->get_label(), $field ) );
|
188 |
+
|
189 |
+
if ( $field->get_description() )
|
190 |
+
$html .= sprintf( '<span class="field-description">(%s)</span>', apply_filters( 'wpbdp_render_field_description', $field->get_description(), $field ) );
|
191 |
+
|
192 |
+
$html .= '</div>';
|
193 |
+
$html .= '<div class="wpbdp-form-field-html wpbdp-form-field-inner">';
|
194 |
+
|
195 |
+
$field_inner = $this->render_field_inner( $field, $value, $render_context, $extra );
|
196 |
+
$field_inner = apply_filters_ref_array( 'wpbdp_render_field_inner', array( $field_inner, &$field, $value, $render_context, &$extra ) );
|
197 |
+
|
198 |
+
$html .= $field_inner;
|
199 |
+
$html .= '</div>';
|
200 |
+
$html .= '</div>';
|
201 |
+
|
202 |
+
break;
|
203 |
+
}
|
204 |
+
|
205 |
+
return $html;
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Called after a field of this type is deleted.
|
210 |
+
* @param object $field the deleted WPBDP_FormField object.
|
211 |
+
*/
|
212 |
+
public function cleanup( &$field ) {
|
213 |
+
if ( $field->get_association() == 'meta' ) {
|
214 |
+
global $wpdb;
|
215 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp[fields][' . $field->get_id() . ']' ) );
|
216 |
+
}
|
217 |
+
|
218 |
+
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Returns an array of valid associations for this field type.
|
223 |
+
* @return array
|
224 |
+
*/
|
225 |
+
public function get_supported_associations() {
|
226 |
+
return array( 'title', 'excerpt', 'content', 'category', 'tags', 'meta' );
|
227 |
+
}
|
228 |
+
|
229 |
+
/**
|
230 |
+
* Renders the field-specific settings area for fields of this type.
|
231 |
+
* It is recommended to use `render_admin_settings` here to keep an uniform look.
|
232 |
+
* `$_POST` values can be used here to populate things when needed.
|
233 |
+
* @param object $field might be NULL if field is new or the field that is being edited.
|
234 |
+
* @param string $association field association.
|
235 |
+
* @return string the HTML output.
|
236 |
+
*/
|
237 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
238 |
+
return '';
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Called when saving fields of this type.
|
243 |
+
* It should be used by field types to store any field type specific configuration.
|
244 |
+
* @param object $field the field being saved.
|
245 |
+
* @return mixed WP_Error in case of error, anything else for success.
|
246 |
+
*/
|
247 |
+
public function process_field_settings( &$field ) {
|
248 |
+
return;
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
/* Utils. */
|
253 |
+
public static function standard_display_wrapper( $labelorfield, $content=null, $extra_classes='', $args=array() ) {
|
254 |
+
$css_classes = 'field-value ';
|
255 |
+
|
256 |
+
if ( is_object( $labelorfield ) ) {
|
257 |
+
if ( $labelorfield->has_display_flag( 'social' ) )
|
258 |
+
return $content;
|
259 |
+
|
260 |
+
$css_classes .= 'wpbdp-field-' . strtolower( str_replace( array( ' ', '/', '(', ')' ), '', $labelorfield->get_label() ) ) . ' ';
|
261 |
+
$css_classes .= 'wpbdp-field-' . $labelorfield->get_association() . ' ';
|
262 |
+
$label = $labelorfield->has_display_flag( 'nolabel' ) ? null : $labelorfield->get_label();
|
263 |
+
} else {
|
264 |
+
$label = $labelorfield;
|
265 |
+
}
|
266 |
+
|
267 |
+
$html = '';
|
268 |
+
$tag_attrs = isset( $args['tag_attrs'] ) ? self::html_attributes( $args['tag_attrs'] ) : '';
|
269 |
+
$html .= '<div class="' . $css_classes . ' ' . $extra_classes . '" ' . $tag_attrs . '>';
|
270 |
+
|
271 |
+
if ( $label )
|
272 |
+
$html .= '<label>' . esc_html( apply_filters( 'wpbdp_display_field_label', $label, $labelorfield ) ) . ':</label> ';
|
273 |
+
|
274 |
+
if ($content)
|
275 |
+
$html .= '<span class="value">' . $content . '</span>';
|
276 |
+
|
277 |
+
$html .= '</div>';
|
278 |
+
|
279 |
+
return $html;
|
280 |
+
}
|
281 |
+
|
282 |
+
public static function render_admin_settings( $admin_settings=array() ) {
|
283 |
+
if ( !$admin_settings )
|
284 |
+
return '';
|
285 |
+
|
286 |
+
$html = '';
|
287 |
+
$html .= '<table class="form-table">';
|
288 |
+
|
289 |
+
foreach ( $admin_settings as $s ) {
|
290 |
+
$label = is_array( $s ) ? $s[0] : '';
|
291 |
+
$content = is_array( $s ) ? $s[1] : $s;
|
292 |
+
|
293 |
+
$html .= '<tr>';
|
294 |
+
if ( $label ) {
|
295 |
+
$html .= '<th scope="row">';
|
296 |
+
$html .= '<label>' . $label . '</label>';
|
297 |
+
$html .= '</th>';
|
298 |
+
}
|
299 |
+
|
300 |
+
$html .= $label ? '<td>' : '<td colspan="2">';
|
301 |
+
$html .= $content;
|
302 |
+
$html .= '</td>';
|
303 |
+
$html .= '</tr>';
|
304 |
+
}
|
305 |
+
|
306 |
+
$html .= '</table>';
|
307 |
+
|
308 |
+
return $html;
|
309 |
+
}
|
310 |
+
|
311 |
+
public static function html_attributes( $attrs, $exceptions = array( 'class' ) ) {
|
312 |
+
$html = '';
|
313 |
+
|
314 |
+
foreach ( $attrs as $k => $v ) {
|
315 |
+
if ( in_array( $k, $exceptions, true ) )
|
316 |
+
continue;
|
317 |
+
|
318 |
+
$html .= sprintf( '%s="%s" ', $k, $v );
|
319 |
+
}
|
320 |
+
|
321 |
+
return $html;
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* @since 3.5.3
|
326 |
+
*/
|
327 |
+
public static function normalize_name( $name ) {
|
328 |
+
$name = strtolower( $name );
|
329 |
+
$name = remove_accents( strip_tags( $name ) );
|
330 |
+
$name = str_replace( array( '/', '"', "'", "\\" ), '', $name );
|
331 |
+
$name = str_replace( ' ', '_', $name );
|
332 |
+
|
333 |
+
return esc_attr( $name );
|
334 |
+
|
335 |
+
}
|
336 |
+
|
337 |
+
}
|
338 |
+
|
339 |
+
/**
|
340 |
+
* @deprecated Since 3.4.2. Use {@link WPBDP_Form_Field_Type} instead.
|
341 |
+
*/
|
342 |
+
class WPBDP_FormFieldType extends WPBDP_Form_Field_Type {}
|
core/class-form-field.php
ADDED
@@ -0,0 +1,614 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Represents a single field from the database. This class can not be instantiated directly.
|
4 |
+
*
|
5 |
+
* @since 2.3
|
6 |
+
*/
|
7 |
+
class WPBDP_Form_Field {
|
8 |
+
|
9 |
+
private $id;
|
10 |
+
private $type;
|
11 |
+
private $association;
|
12 |
+
|
13 |
+
private $label;
|
14 |
+
private $description;
|
15 |
+
|
16 |
+
private $weight = 0;
|
17 |
+
|
18 |
+
private $validators = array();
|
19 |
+
|
20 |
+
private $display_flags = array();
|
21 |
+
private $field_data = array();
|
22 |
+
|
23 |
+
public $css_classes = array();
|
24 |
+
public $html_attributes = array();
|
25 |
+
|
26 |
+
|
27 |
+
public function __construct( $attrs=array() ) {
|
28 |
+
$defaults = array(
|
29 |
+
'id' => 0,
|
30 |
+
'label' => '',
|
31 |
+
'description' => '',
|
32 |
+
'field_type' => 'textfield',
|
33 |
+
'association' => 'meta',
|
34 |
+
'weight' => 0,
|
35 |
+
'validators' => array(),
|
36 |
+
'display_flags' => array(),
|
37 |
+
/*'display_flags' => array( 'excerpt', 'listing', 'search' ),*/
|
38 |
+
'field_data' => array()
|
39 |
+
);
|
40 |
+
|
41 |
+
$attrs = wp_parse_args( $attrs, $defaults );
|
42 |
+
|
43 |
+
$formfields = WPBDP_FormFields::instance();
|
44 |
+
|
45 |
+
$this->id = intval( $attrs['id'] );
|
46 |
+
$this->label = $attrs['label'];
|
47 |
+
$this->description = $attrs['description'];
|
48 |
+
$this->type = is_object( $attrs['field_type'] ) ? $attrs['field_type'] : WPBDP_FormFields::instance()->get_field_type( $attrs['field_type'] );
|
49 |
+
|
50 |
+
if ( !$this->type )
|
51 |
+
throw new Exception( _x( 'Invalid form field type', 'form-fields-api', 'WPBDM' ) );
|
52 |
+
|
53 |
+
/* if ( !$this->type ) // temporary workaround related to 3.0 upgrade issues (issue #365)
|
54 |
+
$this->type = WPBDP_FormFields::instance()->get_field_type( 'textfield' );*/
|
55 |
+
|
56 |
+
$this->association = $attrs['association'];
|
57 |
+
$this->weight = intval( $attrs['weight'] );
|
58 |
+
|
59 |
+
/* Validators */
|
60 |
+
if ( is_array( $attrs['validators'] ) ) {
|
61 |
+
foreach ( $attrs['validators'] as $validator ) {
|
62 |
+
if ( $validator && !in_array( $validator, $this->validators, true ) )
|
63 |
+
$this->validators[] = $validator;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
/* display_options */
|
68 |
+
$this->display_flags = $attrs['display_flags'];
|
69 |
+
$this->field_data = $attrs['field_data'];
|
70 |
+
|
71 |
+
if ( $this->association == 'category' ) {
|
72 |
+
$this->field_data['options'] = array();
|
73 |
+
// } elseif ( $this->association == 'category' ) {
|
74 |
+
// // TODO: make this hierarchical (see https://codex.wordpress.org/Function_Reference/Walker_Class)
|
75 |
+
// $terms = get_terms( $this->association == 'tags' ? WPBDP_TAGS_TAX : wpbdp_categories_taxonomy(), 'hide_empty=0&hierarchical=1' );
|
76 |
+
// $options = array();
|
77 |
+
|
78 |
+
// foreach ( $terms as &$term ) {
|
79 |
+
// $k = $this->association == 'tags' ? $term->slug : $term->term_id;
|
80 |
+
// $options [ $k ] = $term->name;
|
81 |
+
// }
|
82 |
+
|
83 |
+
// $this->field_data['options'] = $options;
|
84 |
+
} else {
|
85 |
+
// handle some special extra data from previous BD versions
|
86 |
+
// TODO: this is not needed anymore since the 3.2 upgrade routine
|
87 |
+
if ( isset( $attrs['field_data'] ) && isset( $attrs['field_data']['options'] ) ) {
|
88 |
+
$options = array();
|
89 |
+
|
90 |
+
foreach ( $attrs['field_data']['options'] as $option_value ) {
|
91 |
+
if ( is_array( $option_value ) )
|
92 |
+
$options[ $option_value[0] ] = $option_value[1];
|
93 |
+
else
|
94 |
+
$options[ $option_value ] = $option_value;
|
95 |
+
}
|
96 |
+
|
97 |
+
$this->field_data['options'] = $options;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
$this->type->setup_field( $this );
|
102 |
+
do_action_ref_array( 'wpbdp_form_field_setup', array( &$this ) );
|
103 |
+
}
|
104 |
+
|
105 |
+
public function get_id() {
|
106 |
+
return $this->id;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function &get_field_type() {
|
110 |
+
return $this->type;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function get_field_type_id() {
|
114 |
+
return $this->type->get_id();
|
115 |
+
}
|
116 |
+
|
117 |
+
public function get_association() {
|
118 |
+
return $this->association;
|
119 |
+
}
|
120 |
+
|
121 |
+
public function get_label() {
|
122 |
+
return $this->label;
|
123 |
+
}
|
124 |
+
|
125 |
+
public function get_description() {
|
126 |
+
return $this->description;
|
127 |
+
}
|
128 |
+
|
129 |
+
public function get_short_name() {
|
130 |
+
global $wpbdp;
|
131 |
+
return $wpbdp->formfields->get_short_names( $this->id );
|
132 |
+
}
|
133 |
+
|
134 |
+
public function &get_validators() {
|
135 |
+
return $this->validators;
|
136 |
+
}
|
137 |
+
|
138 |
+
public function get_weight() {
|
139 |
+
return $this->weight;
|
140 |
+
}
|
141 |
+
|
142 |
+
public function has_validator( $validator ) {
|
143 |
+
return in_array( $validator, $this->validators, true );
|
144 |
+
}
|
145 |
+
|
146 |
+
public function add_validator( $validator ) {
|
147 |
+
if ( !$this->has_validator( $validator ) )
|
148 |
+
$this->validators[] = $validator;
|
149 |
+
}
|
150 |
+
|
151 |
+
public function is_required() {
|
152 |
+
return in_array( 'required', $this->validators, true );
|
153 |
+
}
|
154 |
+
|
155 |
+
public function display_in( $context ) {
|
156 |
+
return in_array( $context, $this->display_flags, true);
|
157 |
+
}
|
158 |
+
|
159 |
+
public function add_display_flag( $flagorflags ) {
|
160 |
+
$flagorflags = is_array( $flagorflags ) ? $flagorflags : array( $flagorflags );
|
161 |
+
|
162 |
+
foreach ( $flagorflags as $flag ) {
|
163 |
+
if ( !$this->has_display_flag( $flag ) ) {
|
164 |
+
$this->display_flags[] = $flag;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
public function remove_display_flag( $flagorflags ) {
|
170 |
+
$flagorflags = is_array( $flagorflags ) ? $flagorflags : array( $flagorflags );
|
171 |
+
|
172 |
+
foreach ( $flagorflags as $flag )
|
173 |
+
wpbdp_array_remove_value( $this->display_flags, $flag );
|
174 |
+
}
|
175 |
+
|
176 |
+
public function has_display_flag( $flag ) {
|
177 |
+
return in_array( $flag, $this->display_flags, true );
|
178 |
+
}
|
179 |
+
|
180 |
+
public function set_display_flags( $flags ) {
|
181 |
+
$this->display_flags = is_array( $flags ) ? $flags : array();
|
182 |
+
}
|
183 |
+
|
184 |
+
public function get_display_flags() {
|
185 |
+
return $this->display_flags;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* @since 3.5.3
|
190 |
+
*/
|
191 |
+
public function get_css_classes( $render_context = '' ) {
|
192 |
+
$css_classes = array();
|
193 |
+
$css_classes[] = 'wpbdp-form-field';
|
194 |
+
$css_classes[] = 'wpbdp-form-field-id-' . $this->get_id();
|
195 |
+
$css_classes[] = 'wpbdp-form-field-type-' . $this->get_field_type()->get_id();
|
196 |
+
$css_classes[] = 'wpbdp-form-field-label-' . WPBDP_Form_Field_Type::normalize_name( $this->get_label() );
|
197 |
+
$css_classes[] = 'wpbdp-form-field-association-' . $this->get_association();
|
198 |
+
|
199 |
+
// For backwards compatibility.
|
200 |
+
$css_classes[] = $this->get_field_type()->get_id();
|
201 |
+
|
202 |
+
if ( $this->get_description() )
|
203 |
+
$css_classes[] = 'with-description';
|
204 |
+
|
205 |
+
if ( $this->get_validators() )
|
206 |
+
$css_classes = array_merge( $css_classes, $this->get_validators() );
|
207 |
+
|
208 |
+
// Add own custom CSS classes.
|
209 |
+
$css_classes = array_merge( $css_classes, $this->css_classes );
|
210 |
+
|
211 |
+
return apply_filters( 'wpbdp_form_field_css_classes', $css_classes, $this, $render_context );
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* TODO: dodoc.
|
216 |
+
* Valid behavior (override default behavior) flags: display-only, no-delete, no-validation
|
217 |
+
* @since 3.4
|
218 |
+
*/
|
219 |
+
public function get_behavior_flags() {
|
220 |
+
return $this->type->get_behavior_flags( $this );
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* TODO: dodoc.
|
225 |
+
* @since 3.4
|
226 |
+
*/
|
227 |
+
public function has_behavior_flag( $flag ) {
|
228 |
+
return in_array( $flag, $this->get_behavior_flags(), true );
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Returns field-type specific configuration options for this field.
|
233 |
+
* @param string $key configuration key name
|
234 |
+
* @return mixed|array if $key is ommitted an array of all key/values will be returned
|
235 |
+
*/
|
236 |
+
public function data( $key=null ) {
|
237 |
+
if ( !$key )
|
238 |
+
return $this->field_data;
|
239 |
+
|
240 |
+
$res = isset( $this->field_data[$key] ) ? $this->field_data[$key] : null;
|
241 |
+
return apply_filters( 'wpbdp_form_field_data', $res, $key, $this );
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Saves field-type specific configuration options for this field.
|
246 |
+
* @param string $key configuration key name.
|
247 |
+
* @param mixed $value data value.
|
248 |
+
* @return mixed data value.
|
249 |
+
*/
|
250 |
+
public function set_data( $key, $value=null ) {
|
251 |
+
$this->field_data[ $key ] = $value;
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Removes any field-type specific configuration option from this field. Use with caution.
|
256 |
+
*/
|
257 |
+
public function clear_data() {
|
258 |
+
$this->field_data = array();
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Returns this field's raw value for the given post.
|
263 |
+
* @param int|object $post_id post ID or object.
|
264 |
+
* @return mixed
|
265 |
+
*/
|
266 |
+
public function value( $post_id, $raw = false ) {
|
267 |
+
if ( !get_post_type( $post_id ) == WPBDP_POST_TYPE )
|
268 |
+
return null;
|
269 |
+
|
270 |
+
$value = $this->type->get_field_value( $this, $post_id );
|
271 |
+
|
272 |
+
if ( ! $raw )
|
273 |
+
$value = apply_filters( 'wpbdp_form_field_value', $value, $post_id, $this );
|
274 |
+
|
275 |
+
return $value;
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Returns this field's HTML value for the given post. Useful for display.
|
280 |
+
* @param int|object $post_id post ID or object.
|
281 |
+
* @return string valid HTML.
|
282 |
+
*/
|
283 |
+
public function html_value( $post_id ) {
|
284 |
+
$value = $this->type->get_field_html_value( $this, $post_id );
|
285 |
+
return apply_filters( 'wpbdp_form_field_html_value', $value , $post_id, $this );
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Returns this field's value as plain text. Useful for emails or cooperation between modules.
|
290 |
+
* @param int|object $post_id post ID or object.
|
291 |
+
* @return string
|
292 |
+
*/
|
293 |
+
public function plain_value( $post_id ) {
|
294 |
+
$value = $this->type->get_field_plain_value( $this, $post_id );
|
295 |
+
return apply_filters( 'wpbdp_form_field_plain_value', $value, $post_id, $this );
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* @since 3.4.1
|
300 |
+
*/
|
301 |
+
public function csv_value( $post_id ) {
|
302 |
+
$value = $this->type->get_field_csv_value( $this, $post_id );
|
303 |
+
return apply_filters( 'wpbdp_form_field_csv_value', $value, $post_id, $this );
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Converts input from forms to a value useful for this field.
|
308 |
+
* @param mixed $input form input.
|
309 |
+
* @return mixed
|
310 |
+
*/
|
311 |
+
public function convert_input( $input=null ) {
|
312 |
+
return $this->type->convert_input( $this, $input );
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* @since 3.4.1
|
317 |
+
*/
|
318 |
+
public function convert_csv_input( $input = '' ) {
|
319 |
+
return $this->type->convert_csv_input( $this, $input );
|
320 |
+
}
|
321 |
+
|
322 |
+
public function store_value( $post_id, $value ) {
|
323 |
+
$this->type->store_field_value( $this, $post_id, $value );
|
324 |
+
do_action_ref_array( 'wpbdp_form_field_store_value', array( &$this, $post_id, $value ) );
|
325 |
+
}
|
326 |
+
|
327 |
+
public function is_empty_value( $value ) {
|
328 |
+
return $this->type->is_empty_value( $value );
|
329 |
+
}
|
330 |
+
|
331 |
+
public function validate( $value, &$errors=null ) {
|
332 |
+
$errors = !is_array( $errors ) ? array() : $errors;
|
333 |
+
|
334 |
+
$validation_api = WPBDP_FieldValidation::instance();
|
335 |
+
|
336 |
+
if ( !$this->is_required() && $this->type->is_empty_value( $value ) )
|
337 |
+
return true;
|
338 |
+
|
339 |
+
foreach ( $this->validators as $validator ) {
|
340 |
+
$res = $validation_api->validate_field( $this, $value, $validator );
|
341 |
+
|
342 |
+
if ( is_wp_error( $res ) ) {
|
343 |
+
$errors[] = $res->get_error_message();
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
if ( !$errors )
|
348 |
+
return true;
|
349 |
+
|
350 |
+
return false;
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Returns HTML apt for display of this field's value.
|
355 |
+
* @param int|object $post_id post ID or object
|
356 |
+
* @param string $display_context the display context. defaults to 'listing'.
|
357 |
+
* @return string
|
358 |
+
*/
|
359 |
+
public function display( $post_id, $display_context='listing' ) {
|
360 |
+
if ( in_array( 'email', $this->validators, true ) && !wpbdp_get_option('override-email-blocking') )
|
361 |
+
return '';
|
362 |
+
|
363 |
+
if ( $this->type->is_empty_value( $this->value( $post_id ) ) )
|
364 |
+
return '';
|
365 |
+
|
366 |
+
$html = $this->type->display_field( $this, $post_id, $display_context );
|
367 |
+
$html = apply_filters_ref_array( 'wpbdp_form_field_display', array( $html, &$this, $display_context, $post_id ) );
|
368 |
+
return $html;
|
369 |
+
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Returns HTML apt for displaying this field in forms.
|
373 |
+
* @param mixed $value the value to be displayed. defaults to null.
|
374 |
+
* @param string $display_context the rendering context. defaults to 'submit'.
|
375 |
+
* @return string
|
376 |
+
*/
|
377 |
+
public function render( $value=null, $display_context='submit', &$extra=null ) {
|
378 |
+
do_action_ref_array( 'wpbdp_form_field_pre_render', array( &$this, $value, $display_context ) );
|
379 |
+
|
380 |
+
if ( $this->has_behavior_flag( 'display-only' ) )
|
381 |
+
return '';
|
382 |
+
|
383 |
+
if ( 'submit' == $display_context && $this->has_behavior_flag( 'no-submit' ) )
|
384 |
+
return '';
|
385 |
+
|
386 |
+
return $this->type->render_field( $this, $value, $display_context, $extra );
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Tries to save this field to the database. If successfully, sets the new id too.
|
391 |
+
* @return mixed True if successfully created, WP_Error in the other case
|
392 |
+
*/
|
393 |
+
public function save() {
|
394 |
+
global $wpdb;
|
395 |
+
|
396 |
+
$api = wpbdp_formfields_api();
|
397 |
+
|
398 |
+
if ( !$this->label || trim( $this->label ) == '' )
|
399 |
+
return new WP_Error( 'wpbdp-save-error', _x('Field label is required.', 'form-fields-api', 'WPBDM') );
|
400 |
+
|
401 |
+
if ( isset( $_POST['field'] ) ) {
|
402 |
+
$res = $this->type->process_field_settings( $this );
|
403 |
+
do_action_ref_array( 'wpbdp_form_field_settings_process', array( &$this ) );
|
404 |
+
|
405 |
+
if ( is_wp_error( $res ) )
|
406 |
+
return $res;
|
407 |
+
}
|
408 |
+
|
409 |
+
// enforce association constraints
|
410 |
+
global $wpbdp;
|
411 |
+
$flags = $wpbdp->formfields->get_association_flags( $this->association );
|
412 |
+
|
413 |
+
if ( in_array( 'unique', $flags ) ) {
|
414 |
+
if ( $otherfields = wpbdp_get_form_fields( 'association=' . $this->association ) ) {
|
415 |
+
if ( ( count( $otherfields ) > 1 ) || ( $otherfields[0]->get_id() != $this->id ) ) {
|
416 |
+
return new WP_Error( 'wpbdp-field-error', sprintf( _x( 'There can only be one field with association "%s". Please select another association.', 'form-fields-api', 'WPBDM' ), $this->association ) );
|
417 |
+
}
|
418 |
+
}
|
419 |
+
}
|
420 |
+
|
421 |
+
if ( in_array( 'required', $flags ) ) {
|
422 |
+
$this->add_validator( 'required' );
|
423 |
+
}
|
424 |
+
|
425 |
+
if ( !in_array( $this->type->get_id(), (array) $wpbdp->formfields->get_association_field_types( $this->association ) ) ) {
|
426 |
+
return new WP_Error( 'wpbdp-field-error', sprintf( _x( '"%s" is an invalid field type for this association.', 'form-fields-api', 'WPBDM' ), $this->type->get_name() ) );
|
427 |
+
}
|
428 |
+
|
429 |
+
$data = array();
|
430 |
+
$data['label'] = $this->label;
|
431 |
+
$data['description'] = trim( $this->description );
|
432 |
+
$data['field_type'] = $this->type->get_id();
|
433 |
+
$data['association'] = $this->association;
|
434 |
+
$data['validators'] = implode( ',', $this->validators );
|
435 |
+
$data['weight'] = $this->weight;
|
436 |
+
$data['display_flags'] = implode( ',', $this->display_flags );
|
437 |
+
$data['field_data'] = serialize( $this->field_data );
|
438 |
+
|
439 |
+
if ( $this->id ) {
|
440 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_form_fields", $data, array( 'id' => $this->id ) );
|
441 |
+
} else {
|
442 |
+
$wpdb->insert( "{$wpdb->prefix}wpbdp_form_fields", $data );
|
443 |
+
$this->id = intval( $wpdb->insert_id );
|
444 |
+
}
|
445 |
+
|
446 |
+
wp_cache_delete( $this->id, 'wpbdp formfields' );
|
447 |
+
|
448 |
+
$api->_calculate_short_names();
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Tries to delete this field from the database.
|
453 |
+
* @return mixed True if successfully deleted, WP_Error in the other case
|
454 |
+
*/
|
455 |
+
public function delete() {
|
456 |
+
if ( !$this->id )
|
457 |
+
return new WP_Error( 'wpbdp-delete-error', _x( 'Invalid field ID', 'form-fields-api', 'WPBDM' ) );
|
458 |
+
|
459 |
+
global $wpbdp;
|
460 |
+
$flags = $wpbdp->formfields->get_association_flags( $this->association );
|
461 |
+
|
462 |
+
if ( in_array( 'required', $flags ) ) {
|
463 |
+
$otherfields = wpbdp_get_form_fields( array( 'association' => $this->association ) );
|
464 |
+
|
465 |
+
if ( !$otherfields || ( $otherfields[0]->get_id() == $this->id ) )
|
466 |
+
return new WP_Error( 'wpbdp-delete-error', _x( "This form field can't be deleted because it is required for the plugin to work.", 'form-fields api', 'WPBDM' ) );
|
467 |
+
}
|
468 |
+
|
469 |
+
global $wpdb;
|
470 |
+
|
471 |
+
if ( $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_form_fields WHERE id = %d", $this->id ) ) !== false ) {
|
472 |
+
$this->type->cleanup( $this );
|
473 |
+
|
474 |
+
wp_cache_delete( $this->id, 'wpbdp formfields' );
|
475 |
+
|
476 |
+
$this->id = 0;
|
477 |
+
} else {
|
478 |
+
return new WP_Error( 'wpbdp-delete-error', _x( 'An error occurred while trying to delete this field.', 'form-fields-api', 'WPBDM' ) );
|
479 |
+
}
|
480 |
+
|
481 |
+
$api = wpbdp_formfields_api();
|
482 |
+
$api->_calculate_short_names();
|
483 |
+
|
484 |
+
return true;
|
485 |
+
}
|
486 |
+
|
487 |
+
/**
|
488 |
+
* Reorders this field within the list of fields.
|
489 |
+
* @param int $delta if positive, field is moved up. else is moved down.
|
490 |
+
*/
|
491 |
+
public function reorder( $delta=0 ) {
|
492 |
+
global $wpdb;
|
493 |
+
|
494 |
+
$delta = intval( $delta );
|
495 |
+
|
496 |
+
if ( !$delta )
|
497 |
+
return;
|
498 |
+
|
499 |
+
if ( $delta > 0 ) {
|
500 |
+
$fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, weight FROM {$wpdb->prefix}wpbdp_form_fields WHERE weight >= %d ORDER BY weight ASC", $this->weight ) );
|
501 |
+
|
502 |
+
if ( $fields[count($fields) - 1]->id == $this->id )
|
503 |
+
return;
|
504 |
+
|
505 |
+
for ( $i = 0; $i < count( $fields ); $i++ ) {
|
506 |
+
$fields[ $i ]->weight = intval( $this->weight ) + $i;
|
507 |
+
|
508 |
+
if ($fields[ $i ]->id == $this->id ) {
|
509 |
+
$fields[ $i ]->weight += 1;
|
510 |
+
$fields[ $i+1 ]->weight -= 1;
|
511 |
+
$i += 1;
|
512 |
+
}
|
513 |
+
}
|
514 |
+
|
515 |
+
foreach ( $fields as &$f ) {
|
516 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_form_fields", array( 'weight' => $f->weight ), array( 'id' => $f->id ) );
|
517 |
+
}
|
518 |
+
} else {
|
519 |
+
$fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, weight FROM {$wpdb->prefix}wpbdp_form_fields WHERE weight <= %d ORDER BY weight ASC", $this->weight ) );
|
520 |
+
|
521 |
+
if ( $fields[0]->id == $this->id )
|
522 |
+
return;
|
523 |
+
|
524 |
+
foreach ( $fields as $i => $f ) {
|
525 |
+
if ( $f->id == $this->id ) {
|
526 |
+
self::get( $fields[ $i-1 ]->id )->reorder( 1 );
|
527 |
+
return;
|
528 |
+
}
|
529 |
+
}
|
530 |
+
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
public function build_quick_search_query( $q = '', &$pieces, $search_term = '', $q_no = 0 ) {
|
535 |
+
global $wpdb;
|
536 |
+
|
537 |
+
$association = $this->get_association();
|
538 |
+
$id = $this->get_id();
|
539 |
+
|
540 |
+
// Do not allow quick search to be performed on e-mail fields for security.
|
541 |
+
if ( $this->has_validator( 'email' ) )
|
542 |
+
return;
|
543 |
+
|
544 |
+
switch ( $association ) {
|
545 |
+
case 'title':
|
546 |
+
case 'excerpt':
|
547 |
+
case 'content':
|
548 |
+
$pieces['fields'] .= "";
|
549 |
+
$pieces['where'] .= $wpdb->prepare( " OR ({$wpdb->posts}.post_{$association} LIKE '%%%s%%')", $q );
|
550 |
+
break;
|
551 |
+
case 'category':
|
552 |
+
case 'tags':
|
553 |
+
case 'region':
|
554 |
+
$tax = WPBDP_CATEGORY_TAX;
|
555 |
+
if ( 'tags' == $association )
|
556 |
+
$tax = WPBDP_TAGS_TAX;
|
557 |
+
elseif ( 'region' == $association && function_exists( 'wpbdp_regions_taxonomy' ) )
|
558 |
+
$tax = wpbdp_regions_taxonomy();
|
559 |
+
|
560 |
+
$pieces['fields'] .= "";
|
561 |
+
$pieces['join'] .= " LEFT JOIN {$wpdb->term_relationships} AS trel{$id}_{$q_no} ON {$wpdb->posts}.ID = trel{$id}_{$q_no}.object_id LEFT JOIN {$wpdb->term_taxonomy} AS ttax{$id}_{$q_no} ON trel{$id}_{$q_no}.term_taxonomy_id = ttax{$id}_{$q_no}.term_taxonomy_id LEFT JOIN {$wpdb->terms} AS tterms{$id}_{$q_no} ON ttax{$id}_{$q_no}.term_id = tterms{$id}_{$q_no}.term_id";
|
562 |
+
$pieces['where'] .= $wpdb->prepare( " OR (ttax{$id}_{$q_no}.taxonomy = %s AND (tterms{$id}_{$q_no}.slug LIKE '%%%s%%' OR tterms{$id}_{$q_no}.name LIKE '%%%s%%'))",
|
563 |
+
$tax, $q, $q );
|
564 |
+
break;
|
565 |
+
case 'meta':
|
566 |
+
$pieces['fields'] .= '';
|
567 |
+
$pieces['join'] .= " LEFT JOIN {$wpdb->postmeta} AS mt{$id}_{$q_no} ON {$wpdb->posts}.ID = mt{$id}_{$q_no}.post_id";
|
568 |
+
$pieces['where'] .= $wpdb->prepare( " OR (mt{$id}_{$q_no}.meta_key = %s AND mt{$id}_{$q_no}.meta_value LIKE '%%%s%%') ",
|
569 |
+
'_wpbdp[fields][' . $id . ']',
|
570 |
+
$q
|
571 |
+
);
|
572 |
+
break;
|
573 |
+
}
|
574 |
+
}
|
575 |
+
|
576 |
+
/**
|
577 |
+
* Creates a WPBDP_FormField from a database record.
|
578 |
+
* @param int $id the database record ID.
|
579 |
+
* @return WPBDP_FormField a valid WPBDP_FormField if the record exists or null if not.
|
580 |
+
*/
|
581 |
+
public static function get( $id ) {
|
582 |
+
global $wpdb;
|
583 |
+
|
584 |
+
$_field = wp_cache_get( $id, 'wpbdp formfields' );
|
585 |
+
|
586 |
+
if ( ! $_field ) {
|
587 |
+
$_field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_form_fields WHERE id = %d", $id ) );
|
588 |
+
|
589 |
+
if ( ! $_field )
|
590 |
+
return null;
|
591 |
+
|
592 |
+
$_field = (array) $_field;
|
593 |
+
|
594 |
+
$_field['display_flags'] = explode( ',', $_field['display_flags'] );
|
595 |
+
$_field['validators'] = explode( ',', $_field['validators'] );
|
596 |
+
$_field['field_data'] = unserialize( $_field['field_data'] );
|
597 |
+
|
598 |
+
wp_cache_set( $id, $_field, 'wpbdp formfields' );
|
599 |
+
}
|
600 |
+
|
601 |
+
try {
|
602 |
+
return new WPBDP_FormField( $_field );
|
603 |
+
} catch (Exception $e ) {
|
604 |
+
return null;
|
605 |
+
}
|
606 |
+
|
607 |
+
}
|
608 |
+
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* @deprecated Since 3.4.2. Use {@link WPBDP_Form_Field} instead.
|
613 |
+
*/
|
614 |
+
class WPBDP_FormField extends WPBDP_Form_Field {}
|
core/class-gateway.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
abstract class WPBDP_Payment_Gateway {
|
4 |
+
|
5 |
+
const INTEGRATION_BUTTON = 'button';
|
6 |
+
const CAPABILITIES_RECURRING = 'recurring';
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
}
|
10 |
+
|
11 |
+
public function get_id() {
|
12 |
+
return '';
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get_gateway_url( $args = array() ) {
|
16 |
+
return add_query_arg( array_merge( array( 'wpbdpx' => 'payments',
|
17 |
+
'action' => 'postback',
|
18 |
+
'gid' => $this->get_id() ),
|
19 |
+
$args ),
|
20 |
+
home_url('/') );
|
21 |
+
}
|
22 |
+
|
23 |
+
public function get_url( &$payment, $action = '' ) {
|
24 |
+
// TODO: support pretty URLs
|
25 |
+
return add_query_arg( array( 'wpbdpx' => 'payments',
|
26 |
+
'action' => $action,
|
27 |
+
'payment_id' => $payment->get_id() ),
|
28 |
+
home_url( '/' ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
public function get_name() {
|
32 |
+
$classname = get_class( $this );
|
33 |
+
$classname = str_replace( 'WPBDP' , '', $classname );
|
34 |
+
$classname = str_replace( '_' , ' ', $classname );
|
35 |
+
$classname = trim( $classname );
|
36 |
+
|
37 |
+
return $classname;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function register_config( &$settings ) { }
|
41 |
+
abstract public function validate_config();
|
42 |
+
|
43 |
+
public function get_supported_currencies() {
|
44 |
+
return array();
|
45 |
+
}
|
46 |
+
|
47 |
+
abstract public function get_integration_method();
|
48 |
+
|
49 |
+
public function get_capabilities() {
|
50 |
+
return array();
|
51 |
+
}
|
52 |
+
|
53 |
+
public function render_unsubscribe_integration( &$category, &$listing) {}
|
54 |
+
|
55 |
+
public function setup_payment( &$payment ) {}
|
56 |
+
|
57 |
+
public function process_generic( $action = '' ) {
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
|
61 |
+
abstract public function process( &$payment, $action );
|
62 |
+
abstract public function render_integration( &$payment );
|
63 |
+
|
64 |
+
|
65 |
+
}
|
core/class-listing-upgrade-api.php
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @since 2.1.6
|
4 |
+
*/
|
5 |
+
class WPBDP_Listing_Upgrade_API {
|
6 |
+
|
7 |
+
private static $instance = null;
|
8 |
+
|
9 |
+
private function __construct() {
|
10 |
+
$this->register_default_levels();
|
11 |
+
}
|
12 |
+
|
13 |
+
public function register_default_levels() {
|
14 |
+
// register default levels
|
15 |
+
$this->register('normal', null, array(
|
16 |
+
'name' => _x('Normal Listing', 'listings-api', 'WPBDM'),
|
17 |
+
'is_sticky' => false
|
18 |
+
));
|
19 |
+
$this->register('sticky', 'normal', array(
|
20 |
+
'name' => _x('Featured Listing', 'listings-api', 'WPBDM'),
|
21 |
+
'cost' => wpbdp_get_option('featured-price'),
|
22 |
+
'description' => wpbdp_get_option('featured-description'),
|
23 |
+
'is_sticky' => true
|
24 |
+
));
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function instance() {
|
28 |
+
if (is_null(self::$instance)) {
|
29 |
+
self::$instance = new self;
|
30 |
+
}
|
31 |
+
|
32 |
+
return self::$instance;
|
33 |
+
}
|
34 |
+
|
35 |
+
/*
|
36 |
+
* General functions.
|
37 |
+
*/
|
38 |
+
public function get_levels() {
|
39 |
+
$res = array();
|
40 |
+
|
41 |
+
foreach ($this->_order as $level_id) {
|
42 |
+
$res[] = $this->get($level_id);
|
43 |
+
}
|
44 |
+
|
45 |
+
return $res;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function register($upgrade_id, $after_id, $data) {
|
49 |
+
if ( !isset($this->_levels) )
|
50 |
+
$this->_levels = array();
|
51 |
+
|
52 |
+
if ( !isset($this->_order) )
|
53 |
+
$this->_order = array();
|
54 |
+
|
55 |
+
if ( empty($upgrade_id) )
|
56 |
+
return false;
|
57 |
+
|
58 |
+
if ( $upgrade_id != 'normal' && (!$after_id || !in_array( $after_id, array_keys ($this->_levels) )) )
|
59 |
+
$after_id = end ( $this->_order );
|
60 |
+
|
61 |
+
$data = array_merge(array(
|
62 |
+
'name' => $upgrade_id,
|
63 |
+
'cost' => 0.0,
|
64 |
+
'description' => '',
|
65 |
+
'is_sticky' => false,
|
66 |
+
'downgrade' => $after_id,
|
67 |
+
'upgrade' => null,
|
68 |
+
), $data);
|
69 |
+
|
70 |
+
if ( !isset($this->_levels[$upgrade_id]) ) {
|
71 |
+
$obj = (object) $data;
|
72 |
+
$obj->id = $upgrade_id;
|
73 |
+
|
74 |
+
if ($obj->downgrade) {
|
75 |
+
$prev_upgrade = $this->next($obj->downgrade);
|
76 |
+
$this->_levels[$obj->downgrade]->upgrade = $obj->id;
|
77 |
+
|
78 |
+
if ($prev_upgrade)
|
79 |
+
$this->_levels[$prev_upgrade]->downgrade = $obj->id;
|
80 |
+
}
|
81 |
+
|
82 |
+
$this->_levels[$upgrade_id] = $obj;
|
83 |
+
} else {
|
84 |
+
// XXX We only allow changes to name, cost and description of currently registered levels.
|
85 |
+
foreach ( array( 'name', 'cost', 'description' ) as $k ) {
|
86 |
+
if ( isset( $data[ $k ] ) )
|
87 |
+
$this->_levels[ $upgrade_id ]->{$k} = $data[ $k ];
|
88 |
+
}
|
89 |
+
|
90 |
+
return;
|
91 |
+
}
|
92 |
+
|
93 |
+
if ($obj->downgrade) {
|
94 |
+
$down_key = array_search($obj->downgrade, $this->_order);
|
95 |
+
|
96 |
+
array_splice($this->_order, max(0, $down_key + 1), 0, array($obj->id));
|
97 |
+
} else {
|
98 |
+
$this->_order[] = $upgrade_id;
|
99 |
+
}
|
100 |
+
|
101 |
+
}
|
102 |
+
|
103 |
+
public function get($upgrade_id) {
|
104 |
+
return wpbdp_getv($this->_levels, $upgrade_id, null);
|
105 |
+
}
|
106 |
+
|
107 |
+
public function prev($upgrade_id) {
|
108 |
+
if ($u = $this->get($upgrade_id))
|
109 |
+
return $u->downgrade;
|
110 |
+
return null;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function next($upgrade_id) {
|
114 |
+
if ($u = $this->get($upgrade_id))
|
115 |
+
return $u->upgrade;
|
116 |
+
return null;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Generates a unique level id from a given name. Useful for plugins extending functionality the
|
121 |
+
* number of featured levels.
|
122 |
+
* @since 2.1.7
|
123 |
+
*/
|
124 |
+
public function unique_id($name) {
|
125 |
+
$key = sanitize_key( $name );
|
126 |
+
|
127 |
+
if ( !in_array( $key, $this->_order ) )
|
128 |
+
return $key;
|
129 |
+
|
130 |
+
$n = 0;
|
131 |
+
while ( true ) {
|
132 |
+
$key = $key . strval( $n );
|
133 |
+
|
134 |
+
if ( !in_array( $key, $this->_order ) )
|
135 |
+
return $key;
|
136 |
+
|
137 |
+
$n += 1;
|
138 |
+
}
|
139 |
+
|
140 |
+
}
|
141 |
+
|
142 |
+
/*
|
143 |
+
* Listing-related.
|
144 |
+
*/
|
145 |
+
|
146 |
+
public function is_sticky($listing_id) {
|
147 |
+
|
148 |
+
// if ($sticky_status = get_post_meta($listing_id, '_wpbdp[sticky]', true)) {
|
149 |
+
// return $sticky_status;
|
150 |
+
// }
|
151 |
+
|
152 |
+
// return 'normal';
|
153 |
+
}
|
154 |
+
|
155 |
+
public function get_listing_level($listing_id) {
|
156 |
+
$sticky_status = get_post_meta( $listing_id, '_wpbdp[sticky]', true );
|
157 |
+
$level = get_post_meta( $listing_id, '_wpbdp[sticky_level]', true );
|
158 |
+
|
159 |
+
switch ($sticky_status) {
|
160 |
+
case 'sticky':
|
161 |
+
if (!$level)
|
162 |
+
return $this->get('sticky');
|
163 |
+
else
|
164 |
+
return $this->get($level) ? $this->get($level) : $this->get('sticky');
|
165 |
+
|
166 |
+
break;
|
167 |
+
case 'pending':
|
168 |
+
if (!$level)
|
169 |
+
return $this->get('normal');
|
170 |
+
else
|
171 |
+
return $this->get($level) ? $this->get($level) : $this->get('sticky');
|
172 |
+
|
173 |
+
break;
|
174 |
+
case 'normal':
|
175 |
+
default:
|
176 |
+
return $this->get('normal');
|
177 |
+
break;
|
178 |
+
}
|
179 |
+
|
180 |
+
}
|
181 |
+
|
182 |
+
public function get_info($listing_id) {
|
183 |
+
if (!$listing_id)
|
184 |
+
return null;
|
185 |
+
|
186 |
+
$sticky_status = get_post_meta( $listing_id, '_wpbdp[sticky]', true );
|
187 |
+
|
188 |
+
$res = new StdClass();
|
189 |
+
$res->level = $this->get_listing_level( $listing_id );
|
190 |
+
$res->status = $sticky_status ? $sticky_status : 'normal';
|
191 |
+
$res->pending = $sticky_status == 'pending' ? true : false;
|
192 |
+
$res->sticky = $res->level->is_sticky;
|
193 |
+
$res->upgradeable = !empty($res->level->upgrade);
|
194 |
+
$res->upgrade = $res->upgradeable ? $this->get($res->level->upgrade) : null;
|
195 |
+
$res->downgradeable = $res->pending ? true : !empty($res->level->downgrade);
|
196 |
+
$res->downgrade = $res->pending ? $this->get($res->level->id) : ($res->downgradeable ? $this->get($res->level->downgrade) : null);
|
197 |
+
|
198 |
+
return $res;
|
199 |
+
}
|
200 |
+
|
201 |
+
public function set_sticky($listing_id, $level_id, $only_upgrade=false) {
|
202 |
+
$current_info = $this->get_info( $listing_id );
|
203 |
+
|
204 |
+
if ( $only_upgrade && (array_search($level_id, $this->_order) < array_search($current_info->level->id, $this->_order)) )
|
205 |
+
return false;
|
206 |
+
|
207 |
+
if ( $level_id == 'normal' ) {
|
208 |
+
delete_post_meta( $listing_id, '_wpbdp[sticky]' );
|
209 |
+
delete_post_meta( $listing_id, '_wpbdp[sticky_level]' );
|
210 |
+
} else {
|
211 |
+
update_post_meta( $listing_id, '_wpbdp[sticky]', 'sticky' );
|
212 |
+
update_post_meta( $listing_id, '_wpbdp[sticky_level]', $level_id );
|
213 |
+
}
|
214 |
+
|
215 |
+
// TODO: approve/cancel transactions related to this operation.
|
216 |
+
}
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
/*
|
221 |
+
* For compat. with other APIs (< 3.5.4)
|
222 |
+
*/
|
223 |
+
class WPBDP_ListingUpgrades extends WPBDP_Listing_Upgrade_API {}
|
224 |
+
|
core/class-listing.php
ADDED
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-payment.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* @since 3.4
|
6 |
+
*/
|
7 |
+
class WPBDP_Listing {
|
8 |
+
|
9 |
+
private $id = 0;
|
10 |
+
private $new = true;
|
11 |
+
|
12 |
+
private function __construct( $id ) {
|
13 |
+
$this->id = intval( $id );
|
14 |
+
}
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Sets the values for listing fields.
|
18 |
+
* @param array $values field_id => value associative array.
|
19 |
+
* @param boolean $append if TRUE the specified field values are set without clearing the values for the other fields.
|
20 |
+
*/
|
21 |
+
public function set_field_values( $values = array(), $append = false ) {
|
22 |
+
$fields = wpbdp_get_form_fields( array( 'association' => array( '-category' ) ) );
|
23 |
+
|
24 |
+
foreach ( $fields as &$f ) {
|
25 |
+
if ( isset( $values[ $f->get_id() ] ) )
|
26 |
+
$f->store_value( $this->id, $values[ $f->get_id() ] );
|
27 |
+
elseif ( ! $append )
|
28 |
+
$f->store_value( $this->id, $f->convert_input( null ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
do_action_ref_array( 'WPBDP_Listing::set_field_values', array( &$this, $values ) );
|
32 |
+
}
|
33 |
+
|
34 |
+
public function get_field_value( $id ) {
|
35 |
+
$field = null;
|
36 |
+
|
37 |
+
if ( is_numeric( $id ) ) {
|
38 |
+
$field = wpbdp_get_form_field( $id );
|
39 |
+
} else {
|
40 |
+
$field = wpbdp_get_form_fields( array( 'association' => $id, 'unique' => true ) );
|
41 |
+
}
|
42 |
+
|
43 |
+
return $field ? $field->html_value( $this->id ) : '';
|
44 |
+
}
|
45 |
+
|
46 |
+
public function get_modified_date() {
|
47 |
+
if ( ! $this->id )
|
48 |
+
return '';
|
49 |
+
|
50 |
+
return date_i18n( get_option( 'date_format' ), get_post_modified_time( 'U', false, $this->id ) );
|
51 |
+
}
|
52 |
+
|
53 |
+
public function get_images( $fields = 'all' ) {
|
54 |
+
$attachments = get_posts( array( 'numberposts' => -1, 'post_type' => 'attachment', 'post_parent' => $this->id ));
|
55 |
+
$result = array();
|
56 |
+
|
57 |
+
foreach ( $attachments as $attachment ) {
|
58 |
+
if ( wp_attachment_is_image( $attachment->ID ) )
|
59 |
+
$result[] = $attachment;
|
60 |
+
}
|
61 |
+
|
62 |
+
if ( 'ids' === $fields )
|
63 |
+
return array_map( create_function( '$x', 'return $x->ID;' ), $result );
|
64 |
+
|
65 |
+
return $result;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Sets listing images.
|
70 |
+
* @param array $images array of image IDs.
|
71 |
+
* @param boolean $append if TRUE images will be appended without clearing previous ones.
|
72 |
+
*/
|
73 |
+
public function set_images( $images = array(), $append = false ) {
|
74 |
+
if ( ! $append ) {
|
75 |
+
$current = $this->get_images( 'ids' );
|
76 |
+
|
77 |
+
foreach ( $current as $img_id ) {
|
78 |
+
if ( ! in_array( $img_id, $images, true ) && wp_attachment_is_image( $img_id ) )
|
79 |
+
wp_delete_attachment( $img_id, true );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
foreach ( $images as $image_id )
|
84 |
+
wp_update_post( array( 'ID' => $image_id, 'post_parent' => $this->id ) );
|
85 |
+
}
|
86 |
+
|
87 |
+
public function set_thumbnail_id( $image_id ) {
|
88 |
+
if ( ! $image_id )
|
89 |
+
return delete_post_meta( $this->id, '_wpbdp[thumbnail_id]' );
|
90 |
+
|
91 |
+
return update_post_meta( $this->id, '_wpbdp[thumbnail_id]', $image_id );
|
92 |
+
}
|
93 |
+
|
94 |
+
public function get_thumbnail_id() {
|
95 |
+
if ( $thumbnail_id = get_post_meta( $this->id, '_wpbdp[thumbnail_id]', true ) ) {
|
96 |
+
return intval( $thumbnail_id );
|
97 |
+
} else {
|
98 |
+
if ( $images = $this->get_images( 'ids' ) ) {
|
99 |
+
update_post_meta( $this->id, '_wpbdp[thumbnail_id]', $images[0] );
|
100 |
+
return $images[0];
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
return 0;
|
105 |
+
}
|
106 |
+
|
107 |
+
public function set_title( $title ) {
|
108 |
+
wp_update_post( array( 'ID' => $this->id, 'post_title' => $title ) );
|
109 |
+
}
|
110 |
+
|
111 |
+
public function get_title() {
|
112 |
+
return get_the_title( $this->id );
|
113 |
+
}
|
114 |
+
|
115 |
+
public function get_id() {
|
116 |
+
return $this->id;
|
117 |
+
}
|
118 |
+
|
119 |
+
|
120 |
+
public function get_category_info( $category ) {
|
121 |
+
$category_id = intval( is_object( $category ) ? $category->term_id : $category );
|
122 |
+
$categories = $this->get_categories( 'all' );
|
123 |
+
|
124 |
+
if ( isset( $categories[ $category_id ] ) )
|
125 |
+
return $categories[ $category_id ];
|
126 |
+
|
127 |
+
return null;
|
128 |
+
}
|
129 |
+
|
130 |
+
public function remove_category( $category, $remove_fee = true, $cleanup = false ) {
|
131 |
+
global $wpdb;
|
132 |
+
|
133 |
+
$category_id = intval( is_object( $category ) ? $category->term_id : $category );
|
134 |
+
|
135 |
+
if ( $remove_fee )
|
136 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d",
|
137 |
+
$this->id,
|
138 |
+
$category_id ) );
|
139 |
+
|
140 |
+
$listing_terms = wp_get_post_terms( $this->id, WPBDP_CATEGORY_TAX, array( 'fields' => 'ids' ) );
|
141 |
+
wpbdp_array_remove_value( $listing_terms, $category_id );
|
142 |
+
wp_set_post_terms( $this->id, $listing_terms, WPBDP_CATEGORY_TAX );
|
143 |
+
|
144 |
+
if ( $cleanup ) {
|
145 |
+
// Remove all payment items related to this category.
|
146 |
+
$payment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT p.id FROM {$wpdb->prefix}wpbdp_payments p WHERE p.listing_id = %d AND
|
147 |
+
p.status = %s AND
|
148 |
+
EXISTS( SELECT 1 FROM {$wpdb->prefix}wpbdp_payments_items pi WHERE pi.payment_id = p.id
|
149 |
+
AND pi.item_type IN (%s, %s) AND pi.rel_id_1 = %d)",
|
150 |
+
$this->id,
|
151 |
+
'pending',
|
152 |
+
'fee',
|
153 |
+
'recurring_fee',
|
154 |
+
$category_id ) );
|
155 |
+
foreach ( $payment_ids as $pid ) {
|
156 |
+
$payment = WPBDP_Payment::get( $pid );
|
157 |
+
$items = $payment->get_items( array( 'item_type' => array( 'fee', 'recurring_fee' ),
|
158 |
+
'rel_id_1' => $category_id ) );
|
159 |
+
foreach ( $items as &$item ) {
|
160 |
+
$payment->delete_item( $item );
|
161 |
+
}
|
162 |
+
|
163 |
+
$payment->save();
|
164 |
+
}
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
// TODO: if there is 'current' information for the category respect the expiration time left.
|
169 |
+
public function add_category( $category, $fee, $recurring = false, $recurring_data = array(), $cleanup = false ) {
|
170 |
+
global $wpdb;
|
171 |
+
|
172 |
+
$this->remove_category( $category, true, $cleanup );
|
173 |
+
|
174 |
+
$category_id = intval( is_object( $category ) ? $category->term_id : $category );
|
175 |
+
$fee = ( null === $fee ) ? $fee : ( is_object( $fee ) ? $fee : wpbdp_get_fee( $fee ) );
|
176 |
+
|
177 |
+
if ( is_null( $fee ) || ! $fee || ! term_exists( $category_id ) )
|
178 |
+
return;
|
179 |
+
|
180 |
+
$fee = (array) $fee;
|
181 |
+
|
182 |
+
$fee_info = array();
|
183 |
+
$fee_info['listing_id'] = $this->id;
|
184 |
+
$fee_info['category_id'] = $category_id;
|
185 |
+
$fee_info['fee_id'] = intval( isset( $fee['id'] ) ? $fee['id'] : ( isset( $fee['fee_id'] ) ? $fee['fee_id'] : 0 ) );
|
186 |
+
$fee_info['fee_days'] = intval( isset( $fee['days'] ) ? $fee['days'] : $fee['fee_days'] );
|
187 |
+
$fee_info['fee_images'] = intval( isset( $fee['images'] ) ? $fee['images'] : $fee['fee_images'] );
|
188 |
+
$fee_info['recurring'] = $recurring ? 1 : 0;
|
189 |
+
|
190 |
+
if ( isset( $recurring_data ) )
|
191 |
+
$fee_info['recurring_data'] = serialize( $recurring_data );
|
192 |
+
|
193 |
+
if ( isset( $recurring_data['recurring_id'] ) )
|
194 |
+
$fee_info['recurring_id'] = $recurring_data['recurring_id'];
|
195 |
+
|
196 |
+
if ( $expiration_date = $this->calculate_expiration_date( time(), $fee ) )
|
197 |
+
$fee_info['expires_on'] = $expiration_date;
|
198 |
+
|
199 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_listing_fees', $fee_info );
|
200 |
+
wp_set_post_terms( $this->id, array( $category_id ), WPBDP_CATEGORY_TAX, true );
|
201 |
+
}
|
202 |
+
|
203 |
+
|
204 |
+
private function calculate_expiration_date( $time, &$fee ) {
|
205 |
+
$days = isset( $fee['days'] ) ? $fee['days'] : $fee['fee_days'];
|
206 |
+
|
207 |
+
if ( 0 == $days )
|
208 |
+
return null;
|
209 |
+
|
210 |
+
$expire_time = strtotime( sprintf( '+%d days', $days ), $time );
|
211 |
+
return date( 'Y-m-d H:i:s', $expire_time );
|
212 |
+
}
|
213 |
+
|
214 |
+
// TODO: what happens when sections clash? i.e. there is a payment pending for a renewal and somehow the category is also in 'expired'
|
215 |
+
public function get_categories( $info = 'current' ) {
|
216 |
+
global $wpdb;
|
217 |
+
|
218 |
+
$current_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT category_id FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND (expires_on >= %s OR expires_on IS NULL)",
|
219 |
+
$this->id,
|
220 |
+
current_time( 'mysql' ) ) );
|
221 |
+
$expired_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT category_id FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND expires_on IS NOT NULL AND expires_on < %s",
|
222 |
+
$this->id,
|
223 |
+
current_time( 'mysql' ) ) );
|
224 |
+
|
225 |
+
// Pending info.
|
226 |
+
$pending_payments = $wpdb->get_results( $wpdb->prepare( "SELECT pi.payment_id, pi.id, pi.rel_id_1 FROM {$wpdb->prefix}wpbdp_payments_items pi INNER JOIN {$wpdb->prefix}wpbdp_payments p ON p.id = pi.payment_id WHERE pi.item_type IN (%s, %s) AND p.status = %s AND p.listing_id = %d",
|
227 |
+
'fee', 'recurring_fee',
|
228 |
+
'pending',
|
229 |
+
$this->id ) );
|
230 |
+
|
231 |
+
$pending = array();
|
232 |
+
foreach ( $pending_payments as &$p ) {
|
233 |
+
$pending[ intval( $p->rel_id_1 ) ] = $p->id;
|
234 |
+
// $pending_payment_ids[ intval( $p->rel_id_1 ) ] = $p->payment_id;
|
235 |
+
}
|
236 |
+
|
237 |
+
$pending_ids = array_keys( $pending );
|
238 |
+
|
239 |
+
$category_ids = array();
|
240 |
+
switch ( $info ) {
|
241 |
+
case 'all':
|
242 |
+
$category_ids = array_merge( $current_ids, $expired_ids, $pending_ids );
|
243 |
+
break;
|
244 |
+
case 'pending':
|
245 |
+
$category_ids = $pending_ids;
|
246 |
+
break;
|
247 |
+
case 'expired':
|
248 |
+
$category_ids = $expired_ids;
|
249 |
+
break;
|
250 |
+
case 'current':
|
251 |
+
default:
|
252 |
+
$category_ids = $current_ids;
|
253 |
+
break;
|
254 |
+
}
|
255 |
+
|
256 |
+
$results = array();
|
257 |
+
|
258 |
+
foreach ( $category_ids as $category_id ) {
|
259 |
+
if ( $category_info = get_term( intval( $category_id ), WPBDP_CATEGORY_TAX ) ) {
|
260 |
+
$category = new StdClass();
|
261 |
+
$category->id = intval( $category_info->term_id );
|
262 |
+
$category->name = $category_info->name;
|
263 |
+
$category->slug = $category_info->slug;
|
264 |
+
$category->term_id = intval( $category_info->term_id );
|
265 |
+
$category->term_taxonomy_id = intval( $category_info->term_taxonomy_id );
|
266 |
+
$category->status = in_array( $category_id, $pending_ids, true ) ? 'pending' : ( in_array( $category_id, $expired_ids, true ) ? 'expired' : 'ok' );
|
267 |
+
|
268 |
+
switch ( $category->status ) {
|
269 |
+
case 'expired':
|
270 |
+
case 'ok':
|
271 |
+
$fee_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d", $this->id, $category_id ) );
|
272 |
+
$fee_info_recurring_data = unserialize( $fee_info->recurring_data );
|
273 |
+
|
274 |
+
if ( ! $fee_info ) {
|
275 |
+
// $this->remove_category( $category_id );
|
276 |
+
continue;
|
277 |
+
}
|
278 |
+
|
279 |
+
$category->fee_id = intval( $fee_info->fee_id );
|
280 |
+
$category->fee_days = intval( $fee_info->fee_days );
|
281 |
+
$category->fee_images = intval( $fee_info->fee_images );
|
282 |
+
|
283 |
+
$category->fee = wpbdp_get_fee( $category->fee_id );
|
284 |
+
if ( ! $category->fee ) {
|
285 |
+
$category->fee = new StdClass();
|
286 |
+
$category->fee->id = $category->fee_id;
|
287 |
+
$category->fee->label = _x( '(Fee Unavailable)', 'listing', 'WPBDM' );
|
288 |
+
$category->fee->amount = 0.0;
|
289 |
+
$category->fee->days = $category->fee_days;
|
290 |
+
$category->fee->images = $category->fee_images;
|
291 |
+
$category->fee->categories = array();
|
292 |
+
$category->fee->extra_data = array();
|
293 |
+
}
|
294 |
+
|
295 |
+
$category->expires_on = $fee_info->expires_on;
|
296 |
+
$category->expired = ( $category->expires_on && strtotime( $category->expires_on ) < time() ) ? true : false;
|
297 |
+
$category->renewal_id = $fee_info->id;
|
298 |
+
$category->recurring = $fee_info->recurring ? true : false;
|
299 |
+
$category->recurring_id = trim( $fee_info->recurring_id );
|
300 |
+
$category->payment_id = isset( $fee_info_recurring_data['payment_id'] ) ? $fee_info_recurring_data['payment_id'] : 0;
|
301 |
+
|
302 |
+
break;
|
303 |
+
|
304 |
+
case 'pending':
|
305 |
+
$payment_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_payments_items WHERE id = %d", $pending[ $category_id ] ) );
|
306 |
+
$payment_info->data = unserialize( $payment_info->data );
|
307 |
+
|
308 |
+
$category->fee_id = intval( $payment_info->rel_id_2 );
|
309 |
+
$category->fee = wpbdp_get_fee( $category->fee_id );
|
310 |
+
if ( ! $category->fee ) {
|
311 |
+
$category->fee = new StdClass();
|
312 |
+
$category->fee->id = $category->fee_id;
|
313 |
+
$category->fee->label = _x( '(Fee Unavailable)', 'listing', 'WPBDM' );
|
314 |
+
$category->fee->amount = 0.0;
|
315 |
+
$category->fee->days = $category->fee_days;
|
316 |
+
$category->fee->images = $category->fee_images;
|
317 |
+
$category->fee->categories = array();
|
318 |
+
$category->fee->extra_data = array();
|
319 |
+
}
|
320 |
+
|
321 |
+
$category->fee_days = intval( $payment_info->data['fee_days'] );
|
322 |
+
$category->fee_images = intval( $payment_info->data['fee_images'] );
|
323 |
+
$category->expires_on = null; // TODO: calculate expiration date.
|
324 |
+
$category->expired = false;
|
325 |
+
$category->renewal_id = 0;
|
326 |
+
$category->recurring = ( 'recurring_fee' == $payment_info->item_type ? true : false );
|
327 |
+
$category->recurring_id = '';
|
328 |
+
$category->payment_id = intval( $payment_info->payment_id );
|
329 |
+
|
330 |
+
break;
|
331 |
+
}
|
332 |
+
|
333 |
+
$results[ $category_id ] = $category;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
|
337 |
+
return $results;
|
338 |
+
}
|
339 |
+
|
340 |
+
public function set_categories( $categories ) {
|
341 |
+
$category_ids = array_map( 'intval', $categories );
|
342 |
+
|
343 |
+
wp_set_post_terms( $this->id, $category_ids, WPBDP_CATEGORY_TAX, false );
|
344 |
+
$this->fix_categories();
|
345 |
+
}
|
346 |
+
|
347 |
+
public function fix_categories( $charge = false ) {
|
348 |
+
global $wpdb;
|
349 |
+
|
350 |
+
// Delete fee information for categories that no longer exist.
|
351 |
+
$wpdb->query( $wpdb->prepare( "DELETE lf FROM {$wpdb->prefix}wpbdp_listing_fees lf WHERE lf.listing_id = %d AND lf.category_id NOT IN (SELECT tt.term_id FROM {$wpdb->term_taxonomy} tt WHERE tt.taxonomy=%s)",
|
352 |
+
$this->id, WPBDP_CATEGORY_TAX ) );
|
353 |
+
|
354 |
+
$terms = wp_get_post_terms( $this->id, WPBDP_CATEGORY_TAX, 'fields=ids' );
|
355 |
+
|
356 |
+
// Remove listing information for categories that no longer apply to the listing.
|
357 |
+
$removed_cats = array_diff( array_keys( $this->get_categories( 'current' ) ), $terms );
|
358 |
+
if ( $removed_cats ) {
|
359 |
+
$cats = implode( ',', $removed_cats );
|
360 |
+
$wpdb->query( $wpdb->prepare( "DELETE lf FROM {$wpdb->prefix}wpbdp_listing_fees lf WHERE lf.listing_id = %d AND lf.category_id IN ({$cats})", $this->id ) );
|
361 |
+
}
|
362 |
+
|
363 |
+
// Assign a default fee for categories without a fee.
|
364 |
+
foreach ( $terms as $category_id ) {
|
365 |
+
$category_info = $this->get_category_info( $category_id );
|
366 |
+
|
367 |
+
if ( $category_info && 'pending' == $category_info->status ) {
|
368 |
+
$this->add_category( $category_id, $category_info->fee, false, null, true );
|
369 |
+
} elseif ( ! $category_info ) {
|
370 |
+
$fee_options = wpbdp_get_fees_for_category( $category_id );
|
371 |
+
|
372 |
+
if ( $charge ) {
|
373 |
+
$payment = new WPBDP_Payment( array( 'listing_id' => $this->id ) );
|
374 |
+
$payment->add_category_fee_item( $category_id, $fee_options[0] );
|
375 |
+
$payment->set_status( WPBDP_Payment::STATUS_COMPLETED );
|
376 |
+
$payment->save();
|
377 |
+
} else {
|
378 |
+
$this->add_category( $category_id, $fee_options[0] );
|
379 |
+
}
|
380 |
+
}
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
public function make_category_non_recurring( $category_id ) {
|
385 |
+
global $wpdb;
|
386 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_listing_fees",
|
387 |
+
array( 'recurring' => 0,
|
388 |
+
'recurring_id' => null,
|
389 |
+
'recurring_data' => null ),
|
390 |
+
array( 'listing_id' => $this->id, 'category_id' => $category_id ) );
|
391 |
+
}
|
392 |
+
|
393 |
+
public function get_total_cost() {
|
394 |
+
global $wpdb;
|
395 |
+
$cost = floatval( $wpdb->get_var( $wpdb->prepare( "SELECT SUM(amount) FROM {$wpdb->prefix}wpbdp_payments WHERE listing_id = %d", $this->id ) ) );
|
396 |
+
return round( $cost, 2 );
|
397 |
+
}
|
398 |
+
|
399 |
+
public function is_published() {
|
400 |
+
return 'publish' == get_post_status( $this->id );
|
401 |
+
}
|
402 |
+
|
403 |
+
public function get_permalink() {
|
404 |
+
if ( ! $this->id )
|
405 |
+
return '';
|
406 |
+
|
407 |
+
return get_permalink( $this->id );
|
408 |
+
}
|
409 |
+
|
410 |
+
public function get_payment_status() {
|
411 |
+
return WPBDP_Payment::find( array( 'listing_id' => $this->id, 'status' => 'pending' ), true ) ? 'pending' : 'ok';
|
412 |
+
}
|
413 |
+
|
414 |
+
public function mark_as_paid() {
|
415 |
+
$pending = WPBDP_Payment::find( array( 'listing_id' => $this->id, 'status' => 'pending' ) );
|
416 |
+
foreach ( $pending as &$p ) {
|
417 |
+
$p->set_status( WPBDP_Payment::STATUS_COMPLETED, 'admin' );
|
418 |
+
$p->save();
|
419 |
+
}
|
420 |
+
}
|
421 |
+
|
422 |
+
public function get_latest_payments() {
|
423 |
+
return WPBDP_Payment::find( array( 'listing_id' => $this->id, '_order' => '-id', '_limit' => 10 ) );
|
424 |
+
}
|
425 |
+
|
426 |
+
public function publish() {
|
427 |
+
if ( ! $this->id )
|
428 |
+
return;
|
429 |
+
|
430 |
+
wp_update_post( array( 'post_status' => 'publish', 'ID' => $this->id ) );
|
431 |
+
}
|
432 |
+
|
433 |
+
public function set_post_status( $status ) {
|
434 |
+
if ( ! $this->id )
|
435 |
+
return;
|
436 |
+
|
437 |
+
wp_update_post( array( 'post_status' => $status, 'ID' => $this->id ) );
|
438 |
+
}
|
439 |
+
|
440 |
+
public function save() {
|
441 |
+
if ( $this->new )
|
442 |
+
do_action_ref_array( 'WPBDP_Listing::listing_created', array( &$this ) );
|
443 |
+
else
|
444 |
+
do_action_ref_array( 'WPBDP_Listing::listing_edited', array( &$this ) );
|
445 |
+
|
446 |
+
$this->new = false;
|
447 |
+
do_action_ref_array( 'WPBDP_Listing::listing_saved', array( &$this ) );
|
448 |
+
|
449 |
+
// do_action( 'wpbdp_save_listing', $listing_id, $data->fields, $data );
|
450 |
+
do_action_ref_array( 'wpbdp_save_listing', array( &$this ) );
|
451 |
+
}
|
452 |
+
|
453 |
+
public function delete() {
|
454 |
+
global $wpdb;
|
455 |
+
$wpdb->update( $wpdb->posts, array( 'post_status' => wpbdp_get_option( 'deleted-status' ) ), array( 'ID' => $this->id ) );
|
456 |
+
clean_post_cache( $this->id );
|
457 |
+
}
|
458 |
+
|
459 |
+
public function notify( $kind = 'save', &$extra = null ) {
|
460 |
+
if ( in_array( $kind, array( 'save', 'edit', 'new' ), true ) )
|
461 |
+
$this->save();
|
462 |
+
|
463 |
+
switch ( $kind ) {
|
464 |
+
case 'save':
|
465 |
+
break;
|
466 |
+
|
467 |
+
case 'edit':
|
468 |
+
do_action_ref_array( 'wpbdp_edit_listing', array( &$this, &$extra ) );
|
469 |
+
break;
|
470 |
+
|
471 |
+
default:
|
472 |
+
break;
|
473 |
+
}
|
474 |
+
}
|
475 |
+
|
476 |
+
/**
|
477 |
+
* @since 3.5.3
|
478 |
+
*/
|
479 |
+
public function get_renewal_hash( $category_id ) {
|
480 |
+
$hash = base64_encode( 'listing_id=' . $this->id . '&category_id=' . $category_id );
|
481 |
+
return $hash;
|
482 |
+
}
|
483 |
+
|
484 |
+
public function get_renewal_url( $category_id ) {
|
485 |
+
$hash = $this->get_renewal_hash( $category_id );
|
486 |
+
return add_query_arg( array( 'action' => 'renewlisting', 'renewal_id' => urlencode( $hash ) ), wpbdp_get_page_link( 'main' ) );
|
487 |
+
}
|
488 |
+
|
489 |
+
public function get_author_meta( $meta ) {
|
490 |
+
if ( ! $this->id )
|
491 |
+
return '';
|
492 |
+
|
493 |
+
$post = get_post( $this->id );
|
494 |
+
return get_the_author_meta( $meta, $post->post_author );
|
495 |
+
}
|
496 |
+
|
497 |
+
public function update( $state ) {
|
498 |
+
// Set title.
|
499 |
+
$title = false;
|
500 |
+
|
501 |
+
if ( isset( $state->title ) ) {
|
502 |
+
$title = $state->title;
|
503 |
+
} else {
|
504 |
+
if ( $title_field = wpbdp_get_form_fields( array( 'association' => 'title', 'unique' => true ) ) ) {
|
505 |
+
if ( isset( $state->fields[ $title_field->get_id() ] ) )
|
506 |
+
$title = $state->fields[ $title_field->get_id() ];
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
if ( $title )
|
511 |
+
$this->set_title( $title );
|
512 |
+
|
513 |
+
// Set categories.
|
514 |
+
if ( isset( $state->categories ) ) {
|
515 |
+
$this->set_categories( $state->categories );
|
516 |
+
}
|
517 |
+
|
518 |
+
if ( isset( $state->fields ) ) {
|
519 |
+
$this->set_field_values( $state->fields );
|
520 |
+
}
|
521 |
+
|
522 |
+
if ( isset( $state->images ) )
|
523 |
+
$this->set_images( $state->images );
|
524 |
+
|
525 |
+
$this->save();
|
526 |
+
}
|
527 |
+
|
528 |
+
public static function create( &$state ) {
|
529 |
+
$title = 'Untitled Listing';
|
530 |
+
|
531 |
+
if ( isset( $state->title ) ) {
|
532 |
+
$title = $state->title;
|
533 |
+
} else {
|
534 |
+
$title_field = wpbdp_get_form_fields( array( 'association' => 'title', 'unique' => true ) );
|
535 |
+
|
536 |
+
if ( isset( $state->fields[ $title_field->get_id() ] ) )
|
537 |
+
$title = $state->fields[ $title_field->get_id() ];
|
538 |
+
}
|
539 |
+
|
540 |
+
$title = trim( strip_tags( $title ) );
|
541 |
+
|
542 |
+
$post_data = array(
|
543 |
+
'post_title' => $title,
|
544 |
+
'post_status' => 'pending',
|
545 |
+
'post_type' => WPBDP_POST_TYPE
|
546 |
+
);
|
547 |
+
|
548 |
+
$post_id = wp_insert_post( $post_data );
|
549 |
+
|
550 |
+
// Create author user if needed.
|
551 |
+
$current_user = wp_get_current_user();
|
552 |
+
|
553 |
+
if ( $current_user->ID == 0 ) {
|
554 |
+
if ( wpbdp_get_option( 'require-login' ) )
|
555 |
+
throw new Exception('Login required.');
|
556 |
+
|
557 |
+
// Create user.
|
558 |
+
if ( $email_field = wpbdp_get_form_fields( array( 'validators' => 'email', 'unique' => 1 ) ) ) {
|
559 |
+
$email = $state->fields[ $email_field->get_id() ];
|
560 |
+
|
561 |
+
if ( email_exists( $email ) ) {
|
562 |
+
$post_author = get_user_by( 'email', $email );
|
563 |
+
$post_author = $post_author->ID;
|
564 |
+
} else {
|
565 |
+
$post_author = wp_insert_user( array(
|
566 |
+
'user_login' => 'guest_' . wp_generate_password( 5, false, false ),
|
567 |
+
'user_email' => $email,
|
568 |
+
'user_pass' => wp_generate_password()
|
569 |
+
) );
|
570 |
+
}
|
571 |
+
|
572 |
+
wp_update_post( array( 'ID' => $post_id, 'post_author' => $post_author ) );
|
573 |
+
}
|
574 |
+
}
|
575 |
+
|
576 |
+
return new self( $post_id );
|
577 |
+
}
|
578 |
+
|
579 |
+
public static function get( $id ) {
|
580 |
+
if ( WPBDP_POST_TYPE !== get_post_type( $id ) )
|
581 |
+
return null;
|
582 |
+
|
583 |
+
$l = new self( $id );
|
584 |
+
$l->new = false;
|
585 |
+
|
586 |
+
return $l;
|
587 |
+
}
|
588 |
+
|
589 |
+
}
|
core/class-listings-api.php
ADDED
@@ -0,0 +1,844 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! class_exists( 'WPBDP_Listings_API' ) ) {
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @since 3.5.4
|
7 |
+
*/
|
8 |
+
class WPBDP_Listings_API {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
add_filter( 'post_type_link', array( &$this, '_post_link' ), 10, 4 );
|
12 |
+
add_filter( 'get_shortlink', array( &$this, '_short_link' ), 10, 4 );
|
13 |
+
add_filter('post_type_link', array($this, '_post_link_qtranslate'), 11, 2); // basic support for qTranslate
|
14 |
+
add_filter('preview_post_link', array($this, '_preview_post_link'), 10, 1);
|
15 |
+
|
16 |
+
add_filter('term_link', array($this, '_category_link'), 10, 3);
|
17 |
+
add_filter('term_link', array($this, '_tag_link'), 10, 3);
|
18 |
+
add_filter('comments_open', array($this, '_allow_comments'), 10, 2);
|
19 |
+
|
20 |
+
add_action( 'wpbdp_after_single_view', array( &$this, '_show_contact_form' ), 0 );
|
21 |
+
|
22 |
+
add_action( 'WPBDP_Listing::listing_created', array( &$this, 'new_listing_admin_email' ) );
|
23 |
+
add_action( 'WPBDP_Listing::listing_created', array( &$this, 'new_listing_confirmation_email' ) );
|
24 |
+
add_action( 'wpbdp_edit_listing', array( &$this, 'edit_listing_admin_email' ) );
|
25 |
+
|
26 |
+
add_action( 'WPBDP_Payment::status_change', array( &$this, 'setup_listing_after_payment' ) );
|
27 |
+
add_action( 'WPBDP_Payment::status_change', array( &$this, 'auto_renewal_notification_email' ) );
|
28 |
+
|
29 |
+
add_action( 'transition_post_status', array( &$this, 'listing_published_notification' ), 10, 3 );
|
30 |
+
|
31 |
+
add_action( 'before_delete_post', array( &$this, 'after_listing_delete' ) );
|
32 |
+
|
33 |
+
$this->upgrades = WPBDP_Listing_Upgrade_API::instance();
|
34 |
+
}
|
35 |
+
|
36 |
+
public function _category_link($link, $category, $taxonomy) {
|
37 |
+
if ( WPBDP_CATEGORY_TAX != $taxonomy )
|
38 |
+
return $link;
|
39 |
+
|
40 |
+
if ( 'page' == _wpbdp_template_mode( 'category' ) ) {
|
41 |
+
if ( wpbdp_rewrite_on() )
|
42 |
+
$link = rtrim( wpbdp_get_page_link( 'main' ), '/' ) . '/' . wpbdp_get_option( 'permalinks-category-slug' ) . '/' . $category->slug . '/';
|
43 |
+
else
|
44 |
+
$link = add_query_arg( 'category', $category->slug, wpbdp_get_page_link( 'main' ) );
|
45 |
+
}
|
46 |
+
|
47 |
+
return apply_filters( 'wpbdp_category_link', $link, $category );
|
48 |
+
}
|
49 |
+
|
50 |
+
public function _tag_link($link, $tag, $taxonomy) {
|
51 |
+
if ( ($taxonomy == WPBDP_TAGS_TAX) && (_wpbdp_template_mode('category') == 'page') ) {
|
52 |
+
if (wpbdp_rewrite_on()) {
|
53 |
+
return rtrim(wpbdp_get_page_link('main'), '/') . '/' . wpbdp_get_option('permalinks-tags-slug') . '/' . $tag->slug . '/';
|
54 |
+
} else {
|
55 |
+
return add_query_arg('tag', $tag->slug, wpbdp_get_page_link('main'));
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
return $link;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function _post_link( $url, $post = null, $leavename = false, $sample = false ) {
|
63 |
+
if ( WPBDP_POST_TYPE != get_post_type( $post ) || ! wpbdp_get_page_id( 'main' ) )
|
64 |
+
return $url;
|
65 |
+
|
66 |
+
if ( 'page' != _wpbdp_template_mode( 'single' ) )
|
67 |
+
return $url;
|
68 |
+
|
69 |
+
$rewrite = wpbdp_rewrite_on();
|
70 |
+
$baseurl = untrailingslashit( wpbdp_get_page_link( 'main' ) );
|
71 |
+
$querystring = parse_url( $url, PHP_URL_QUERY );
|
72 |
+
|
73 |
+
if ( $sample && $rewrite ) {
|
74 |
+
return rtrim( wpbdp_get_page_link( 'main' ), '/' ) . '/' . '%' . WPBDP_POST_TYPE . '%' . '/' . ( $querystring ? '?' . $querystring : '' );
|
75 |
+
}
|
76 |
+
|
77 |
+
// if ( $leavename ) {
|
78 |
+
// return $url;
|
79 |
+
// }
|
80 |
+
|
81 |
+
if ( $rewrite ) {
|
82 |
+
if ( wpbdp_get_option( 'permalinks-no-id' ) && $post->post_name )
|
83 |
+
$url = $baseurl . '/' . $post->post_name . '/' . ( $querystring ? '?' . $querystring : '' );
|
84 |
+
else
|
85 |
+
$url = $baseurl . '/' . $post->ID . '/' . ( $post->post_name ? $post->post_name . '/' : '' ) . ( $querystring ? '?' . $querystring : '' );
|
86 |
+
} else {
|
87 |
+
$url = add_query_arg( 'id', $post->ID, $baseurl );
|
88 |
+
}
|
89 |
+
|
90 |
+
return apply_filters( 'wpbdp_listing_link', $url, $post->ID );
|
91 |
+
}
|
92 |
+
|
93 |
+
public function _short_link( $shortlink, $id = 0, $context = 'post', $allow_slugs = true ) {
|
94 |
+
if ( 'post' !== $context )
|
95 |
+
return $shortlink;
|
96 |
+
|
97 |
+
$post = get_post( $id );
|
98 |
+
|
99 |
+
if ( WPBDP_POST_TYPE != $post->post_type )
|
100 |
+
return $shortlink;
|
101 |
+
|
102 |
+
return $this->_post_link( $shortlink, $post );
|
103 |
+
}
|
104 |
+
|
105 |
+
public function _post_link_qtranslate( $url, $post ) {
|
106 |
+
if ( is_admin() || !function_exists( 'qtrans_convertURL' ) )
|
107 |
+
return $url;
|
108 |
+
|
109 |
+
global $q_config;
|
110 |
+
|
111 |
+
$lang = isset( $_GET['lang'] ) ? $_GET['lang'] : $q_config['language'];
|
112 |
+
$default_lang = $q_config['default_language'];
|
113 |
+
|
114 |
+
if ( $lang != $default_lang )
|
115 |
+
return add_query_arg( 'lang', $lang, $url );
|
116 |
+
|
117 |
+
return $url;
|
118 |
+
}
|
119 |
+
|
120 |
+
public function _preview_post_link( $url ) {
|
121 |
+
return $url;
|
122 |
+
}
|
123 |
+
|
124 |
+
public function _allow_comments($open, $post_id) {
|
125 |
+
// comments on directory pages
|
126 |
+
if ($post_id == wpbdp_get_page_id('main'))
|
127 |
+
return false;
|
128 |
+
|
129 |
+
// comments on listings
|
130 |
+
if (get_post_type($post_id) == WPBDP_POST_TYPE)
|
131 |
+
return wpbdp_get_option('show-comment-form');
|
132 |
+
|
133 |
+
return $open;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* @since 3.5.3
|
138 |
+
*/
|
139 |
+
function _show_contact_form( $listing_id ) {
|
140 |
+
if ( ! class_exists( 'WPBDP_Listing_Contact_View' ) )
|
141 |
+
require_once( WPBDP_PATH . 'core/view-listing-contact.php' );
|
142 |
+
|
143 |
+
$v = new WPBDP_Listing_Contact_View();
|
144 |
+
echo $v->render_form( $listing_id );
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* @since 3.4
|
149 |
+
*/
|
150 |
+
public function setup_listing_after_payment( &$payment ) {
|
151 |
+
$listing = WPBDP_Listing::get( $payment->get_listing_id() );
|
152 |
+
|
153 |
+
// TODO: handle some rejected payments (i.e. downgrade listing if pending upgrade, etc.)
|
154 |
+
|
155 |
+
if ( ! $listing || ! $payment->is_completed() )
|
156 |
+
return;
|
157 |
+
|
158 |
+
foreach ( $payment->get_items() as $item ) {
|
159 |
+
switch ( $item->item_type ) {
|
160 |
+
case 'recurring_fee':
|
161 |
+
$listing->add_category( $item->rel_id_1, (object) $item->data, true, array( 'recurring_id' => $payment->get_data( 'recurring_id' ),
|
162 |
+
'payment_id' => $payment->get_id() ) );
|
163 |
+
break;
|
164 |
+
case 'fee':
|
165 |
+
$listing->add_category( $item->rel_id_1, $item->rel_id_2, false );
|
166 |
+
break;
|
167 |
+
|
168 |
+
case 'upgrade':
|
169 |
+
$upgrades_api = wpbdp_listing_upgrades_api();
|
170 |
+
$sticky_info = $upgrades_api->get_info( $listing->get_id() );
|
171 |
+
|
172 |
+
if ( $sticky_info->upgradeable )
|
173 |
+
$upgrades_api->set_sticky( $listing->get_id(), $sticky_info->upgrade->id, true );
|
174 |
+
|
175 |
+
break;
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
$listing->save();
|
180 |
+
// $listing->maybe_publish();
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* @since 3.5.2
|
185 |
+
*/
|
186 |
+
public function auto_renewal_notification_email( &$payment ) {
|
187 |
+
if ( ! $payment->is_completed() || ! $payment->has_item_type( 'recurring_fee' ) )
|
188 |
+
return;
|
189 |
+
|
190 |
+
if ( ! $payment->get_data( 'parent_payment_id' ) )
|
191 |
+
return;
|
192 |
+
|
193 |
+
$recurring_item = $payment->get_recurring_item();
|
194 |
+
|
195 |
+
$replacements = array();
|
196 |
+
$replacements['listing'] = sprintf( '<a href="%s">%s</a>',
|
197 |
+
get_permalink( $payment->get_listing_id() ),
|
198 |
+
get_the_title( $payment->get_listing_id() ) );
|
199 |
+
$replacements['author'] = get_the_author_meta( 'display_name', get_post( $payment->get_listing_id() )->post_author );
|
200 |
+
$replacements['category'] = wpbdp_get_term_name( $recurring_item->rel_id_1 );
|
201 |
+
$replacements['date'] = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
|
202 |
+
strtotime( $payment->get_processed_on() ) );
|
203 |
+
$replacements['site'] = sprintf( '<a href="%s">%s</a>',
|
204 |
+
get_bloginfo( 'url' ),
|
205 |
+
get_bloginfo( 'name' ) );
|
206 |
+
|
207 |
+
$email = wpbdp_email_from_template( 'listing-autorenewal-message', $replacements );
|
208 |
+
$email->to[] = wpbusdirman_get_the_business_email( $payment->get_listing_id() );
|
209 |
+
$email->send();
|
210 |
+
}
|
211 |
+
|
212 |
+
function listing_published_notification( $new_status, $old_status, $post ) {
|
213 |
+
if ( ! in_array( 'listing-published', wpbdp_get_option( 'user-notifications' ), true ) )
|
214 |
+
return;
|
215 |
+
|
216 |
+
if ( WPBDP_POST_TYPE != get_post_type( $post ) )
|
217 |
+
return;
|
218 |
+
|
219 |
+
if ( $new_status == $old_status || 'publish' != $new_status || ( 'pending' != $old_status && 'draft' != $old_status ) )
|
220 |
+
return;
|
221 |
+
|
222 |
+
$email = wpbdp_email_from_template( 'email-templates-listing-published', array(
|
223 |
+
'listing' => get_the_title( $post->ID ),
|
224 |
+
'listing-url' => get_permalink( $post->ID )
|
225 |
+
) );
|
226 |
+
$email->to[] = wpbusdirman_get_the_business_email( $post->ID );
|
227 |
+
$email->send();
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Handles cleanup after a listing is deleted.
|
232 |
+
* @since 3.4
|
233 |
+
*/
|
234 |
+
public function after_listing_delete( $post_id ) {
|
235 |
+
global $wpdb;
|
236 |
+
|
237 |
+
if ( WPBDP_POST_TYPE != get_post_type( $post_id ) )
|
238 |
+
return;
|
239 |
+
|
240 |
+
// Remove attachments.
|
241 |
+
$attachments = get_posts( array( 'post_type' => 'attachment', 'post_parent' => $post_id, 'numberposts' => -1, 'fields' => 'ids' ) );
|
242 |
+
foreach ( $attachments as $attachment_id )
|
243 |
+
wp_delete_attachment( $attachment_id, true );
|
244 |
+
|
245 |
+
// Remove listing fees.
|
246 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d", $post_id ) );
|
247 |
+
|
248 |
+
// Remove payment information.
|
249 |
+
$wpdb->query( $wpdb->prepare( "DELETE pi.* FROM {$wpdb->prefix}wpbdp_payments_items pi WHERE pi.payment_id IN (SELECT p.id FROM {$wpdb->prefix}wpbdp_payments p WHERE p.listing_id = %d)", $post_id ) );
|
250 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments WHERE listing_id = %d", $post_id ) );
|
251 |
+
}
|
252 |
+
|
253 |
+
|
254 |
+
|
255 |
+
public function new_listing_confirmation_email( &$listing ) {
|
256 |
+
if ( ! in_array( 'new-listing', wpbdp_get_option( 'user-notifications' ), true ) )
|
257 |
+
return;
|
258 |
+
|
259 |
+
$email = wpbdp_email_from_template( 'email-confirmation-message', array(
|
260 |
+
'listing' => $listing->get_title()
|
261 |
+
) );
|
262 |
+
$email->to[] = wpbusdirman_get_the_business_email( $listing->get_id() );
|
263 |
+
$email->send();
|
264 |
+
}
|
265 |
+
|
266 |
+
public function new_listing_admin_email( &$listing ) {
|
267 |
+
if ( ! in_array( 'new-listing', wpbdp_get_option( 'admin-notifications' ), true ) )
|
268 |
+
return;
|
269 |
+
|
270 |
+
$email = new WPBDP_Email();
|
271 |
+
$email->subject = sprintf( _x( '[%s] New listing notification', 'notify email', 'WPBDM' ), get_bloginfo( 'name' ) );
|
272 |
+
$email->to[] = get_bloginfo( 'admin_email' );
|
273 |
+
|
274 |
+
if ( wpbdp_get_option( 'admin-notifications-cc' ) )
|
275 |
+
$email->cc[] = wpbdp_get_option( 'admin-notifications-cc' );
|
276 |
+
|
277 |
+
$email->body = wpbdp_render( 'email/listing-added', array( 'listing' => $listing ), false );
|
278 |
+
$email->send();
|
279 |
+
}
|
280 |
+
|
281 |
+
public function edit_listing_admin_email( &$listing ) {
|
282 |
+
if ( ! in_array( 'listing-edit', wpbdp_get_option( 'admin-notifications' ), true ) )
|
283 |
+
return;
|
284 |
+
|
285 |
+
$email = new WPBDP_Email();
|
286 |
+
$email->subject = sprintf( _x( '[%s] Listing edit notification', 'notify email', 'WPBDM' ), get_bloginfo( 'name' ) );
|
287 |
+
$email->to[] = get_bloginfo( 'admin_email' );
|
288 |
+
|
289 |
+
if ( wpbdp_get_option( 'admin-notifications-cc' ) )
|
290 |
+
$email->cc[] = wpbdp_get_option( 'admin-notifications-cc' );
|
291 |
+
|
292 |
+
$email->body = wpbdp_render( 'email/listing-edited', array( 'listing' => $listing ), false );
|
293 |
+
|
294 |
+
$email->send();
|
295 |
+
}
|
296 |
+
|
297 |
+
public function get_thumbnail_id($listing_id) {
|
298 |
+
if ( $thumbnail_id = get_post_meta($listing_id, '_wpbdp[thumbnail_id]', true ) ) {
|
299 |
+
if ( false !== get_post_status( $thumbnail_id ) )
|
300 |
+
return intval( $thumbnail_id );
|
301 |
+
}
|
302 |
+
|
303 |
+
if ( $images = $this->get_images( $listing_id ) ) {
|
304 |
+
update_post_meta( $listing_id, '_wpbdp[thumbnail_id]', $images[0]->ID );
|
305 |
+
return $images[0]->ID;
|
306 |
+
}
|
307 |
+
|
308 |
+
return 0;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* @since 3.4.1
|
313 |
+
*/
|
314 |
+
public function calculate_sequence_id( $listing_id ) {
|
315 |
+
$sequence_id = get_post_meta( $listing_id, '_wpbdp[import_sequence_id]', true );
|
316 |
+
|
317 |
+
if ( ! $sequence_id ) {
|
318 |
+
global $wpdb;
|
319 |
+
$candidate = intval( $wpdb->get_var( $wpdb->prepare( "SELECT (MAX(meta_value) + 1) FROM {$wpdb->postmeta} WHERE meta_key = %s",
|
320 |
+
'_wpbdp[import_sequence_id]' ) ) );
|
321 |
+
|
322 |
+
if ( false == add_post_meta( $listing_id, '_wpbdp[import_sequence_id]', $candidate, true ) )
|
323 |
+
$sequence_id = 0;
|
324 |
+
else
|
325 |
+
$sequence_id = $candidate;
|
326 |
+
}
|
327 |
+
|
328 |
+
return $sequence_id;
|
329 |
+
}
|
330 |
+
|
331 |
+
public function get_images($listing_id) {
|
332 |
+
$attachments = get_posts(array(
|
333 |
+
'numberposts' => -1,
|
334 |
+
'post_type' => 'attachment',
|
335 |
+
'post_parent' => $listing_id
|
336 |
+
));
|
337 |
+
|
338 |
+
$result = array();
|
339 |
+
|
340 |
+
foreach ($attachments as $attachment) {
|
341 |
+
if (wp_attachment_is_image($attachment->ID))
|
342 |
+
$result[] = $attachment;
|
343 |
+
}
|
344 |
+
|
345 |
+
return $result;
|
346 |
+
}
|
347 |
+
|
348 |
+
public function get_listing_fees($listing_id) {
|
349 |
+
global $wpdb;
|
350 |
+
return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d", $listing_id));
|
351 |
+
}
|
352 |
+
|
353 |
+
public function remove_category_info( $listing_id, $category_or_categories ) {
|
354 |
+
global $wpdb;
|
355 |
+
|
356 |
+
$categories = array_map( 'intval', is_array( $category_or_categories ) ? $category_or_categories : array( $category_or_categories ) );
|
357 |
+
$current_terms = array_map( 'intval', wp_get_post_terms( $listing_id, WPBDP_CATEGORY_TAX, 'fields=ids' ) );
|
358 |
+
$new_terms = array_diff( $current_terms, $categories );
|
359 |
+
|
360 |
+
wp_set_post_terms( $listing_id, $new_terms, WPBDP_CATEGORY_TAX, false );
|
361 |
+
|
362 |
+
foreach ( $categories as $cat_id ) {
|
363 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d",
|
364 |
+
$listing_id,
|
365 |
+
$cat_id ) );
|
366 |
+
}
|
367 |
+
|
368 |
+
return true;
|
369 |
+
}
|
370 |
+
|
371 |
+
public function get_expiration_time($listing_id, $fee) {
|
372 |
+
if (is_array($fee)) return $this->get_expiration_time($listing_id, (object) $fee);
|
373 |
+
|
374 |
+
if ($fee->days == 0)
|
375 |
+
return null;
|
376 |
+
|
377 |
+
$start_time = get_post_time('U', false, $listing_id);
|
378 |
+
$expire_time = strtotime(sprintf('+%d days', $fee->days), $start_time);
|
379 |
+
return $expire_time;
|
380 |
+
}
|
381 |
+
|
382 |
+
public function get_listing_fee_for_category($listing_id, $catid) {
|
383 |
+
global $wpdb;
|
384 |
+
|
385 |
+
$row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND category_id = %d", $listing_id, $catid));
|
386 |
+
|
387 |
+
if ($row != null) {
|
388 |
+
// $fee = unserialize($row->fee);
|
389 |
+
$fee['expires_on'] = $row->expires_on;
|
390 |
+
$fee['renewal_id'] = $row->id;
|
391 |
+
$fee['category_id'] = $row->category_id;
|
392 |
+
return (object) $fee;
|
393 |
+
}
|
394 |
+
|
395 |
+
return null;
|
396 |
+
}
|
397 |
+
|
398 |
+
/*
|
399 |
+
* Featured listings.
|
400 |
+
*/
|
401 |
+
|
402 |
+
// TODO: deprecate (move to ListingUpgrades)
|
403 |
+
public function get_sticky_status($listing_id) {
|
404 |
+
if ($sticky_status = get_post_meta($listing_id, '_wpbdp[sticky]', true)) {
|
405 |
+
return $sticky_status;
|
406 |
+
}
|
407 |
+
|
408 |
+
return 'normal';
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Automatically renews a listing in all of its expired categories using the same fee as before (if possible) or the first one available.
|
413 |
+
* @param int $listing_id the listing ID
|
414 |
+
* @since 3.1
|
415 |
+
*/
|
416 |
+
public function auto_renew( $listing_id ) {
|
417 |
+
global $wpdb;
|
418 |
+
|
419 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
420 |
+
$expired = $listing->get_categories( 'expired' );
|
421 |
+
|
422 |
+
if ( !$expired )
|
423 |
+
return;
|
424 |
+
|
425 |
+
foreach ( $expired as &$e ) {
|
426 |
+
$available_fees = wpbdp_get_fees_for_category( $e->term_id );
|
427 |
+
$old_fee_id = $e->fee_id;
|
428 |
+
$new_fee = null;
|
429 |
+
|
430 |
+
foreach ( $available_fees as &$fee_option ) {
|
431 |
+
if ( $fee_option->id == $old_fee_id ) {
|
432 |
+
$new_fee = $fee_option;
|
433 |
+
break;
|
434 |
+
}
|
435 |
+
}
|
436 |
+
|
437 |
+
if ( !$new_fee )
|
438 |
+
$new_fee = $available_fees[0];
|
439 |
+
|
440 |
+
$listing->add_category( $e->term_id, $new_fee );
|
441 |
+
}
|
442 |
+
|
443 |
+
wp_update_post( array( 'ID' => $listing_id, 'post_status' => 'publish' ) );
|
444 |
+
}
|
445 |
+
|
446 |
+
public function renew_listing($renewal_id, $fee) {
|
447 |
+
global $wpdb;
|
448 |
+
|
449 |
+
if ( $renewal = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d AND expires_on IS NOT NULL", $renewal_id, current_time( 'mysql' ) ) ) ) {
|
450 |
+
// set payment status to not-paid
|
451 |
+
// update_post_meta( $renewal->listing_id, '_wpbdp[payment_status]', 'not-paid' );
|
452 |
+
|
453 |
+
// register the new transaction
|
454 |
+
$transaction_id = wpbdp_payments_api()->save_transaction( array(
|
455 |
+
'listing_id' => $renewal->listing_id,
|
456 |
+
'amount' => $fee->amount,
|
457 |
+
'payment_type' => 'renewal',
|
458 |
+
'extra_data' => array( 'renewal_id' => $renewal_id, 'fee' => $fee )
|
459 |
+
));
|
460 |
+
|
461 |
+
return $transaction_id;
|
462 |
+
}
|
463 |
+
|
464 |
+
return 0;
|
465 |
+
}
|
466 |
+
|
467 |
+
// {{{ Quick search.
|
468 |
+
|
469 |
+
private function get_quick_search_fields() {
|
470 |
+
$fields = array();
|
471 |
+
|
472 |
+
foreach ( wpbdp_get_option( 'quick-search-fields', array() ) as $field_id ) {
|
473 |
+
if ( $field = WPBDP_FormField::get( $field_id ) )
|
474 |
+
$fields[] = $field;
|
475 |
+
}
|
476 |
+
|
477 |
+
if ( ! $fields ) {
|
478 |
+
// Use default fields.
|
479 |
+
foreach( wpbdp_get_form_fields() as $field ) {
|
480 |
+
if ( in_array( $field->get_association(), array( 'title', 'excerpt', 'content' ) ) )
|
481 |
+
$fields[] = $field;
|
482 |
+
}
|
483 |
+
}
|
484 |
+
|
485 |
+
return $fields;
|
486 |
+
}
|
487 |
+
|
488 |
+
/**
|
489 |
+
* Performs a "quick search" for listings on the fields marked as quick-search fields in the plugin settings page.
|
490 |
+
* @uses WPBDP_ListingsAPI::get_quick_search_fields().
|
491 |
+
* @param string $q The string used for searching.
|
492 |
+
* @return array The listing IDs.
|
493 |
+
* @since 3.4
|
494 |
+
*/
|
495 |
+
public function quick_search( $q = '' ) {
|
496 |
+
$q = trim( $q );
|
497 |
+
|
498 |
+
if ( ! $q )
|
499 |
+
return array();
|
500 |
+
|
501 |
+
global $wpdb;
|
502 |
+
|
503 |
+
$fields = $this->get_quick_search_fields();
|
504 |
+
$query_pieces = array( 'where' => '',
|
505 |
+
'join' => '',
|
506 |
+
'orderby' => '',
|
507 |
+
'distinct' => '',
|
508 |
+
'fields' => "{$wpdb->posts}.ID",
|
509 |
+
'limits' => '' );
|
510 |
+
|
511 |
+
$words = array_map( 'trim', explode( ' ', $q ) );
|
512 |
+
|
513 |
+
$query_pieces['where'] .= '';
|
514 |
+
|
515 |
+
foreach ( $words as $i => $w ) {
|
516 |
+
$query_pieces['where'] .= ' AND ( 1=0 ';
|
517 |
+
|
518 |
+
foreach ( $fields as &$f ) {
|
519 |
+
$f->build_quick_search_query( $w, $query_pieces, $q, $i );
|
520 |
+
}
|
521 |
+
|
522 |
+
$query_pieces['where'] .= ' )';
|
523 |
+
}
|
524 |
+
|
525 |
+
$query_pieces = apply_filters( 'wpbdp_quick_search_query_pieces', $query_pieces );
|
526 |
+
$query = sprintf( "SELECT %s %s FROM {$wpdb->posts} %s WHERE 1=1 %s GROUP BY {$wpdb->posts}.ID %s %s",
|
527 |
+
$query_pieces['distinct'],
|
528 |
+
$query_pieces['fields'],
|
529 |
+
$query_pieces['join'],
|
530 |
+
$query_pieces['where'],
|
531 |
+
$query_pieces['orderby'],
|
532 |
+
$query_pieces['limits'] );
|
533 |
+
|
534 |
+
return $wpdb->get_col( $query );
|
535 |
+
}
|
536 |
+
|
537 |
+
// }}}
|
538 |
+
|
539 |
+
/* listings search */
|
540 |
+
public function search($args) {
|
541 |
+
global $wpdb;
|
542 |
+
|
543 |
+
$term = str_replace('*', '', trim(wpbdp_getv($args, 'q', '')));
|
544 |
+
|
545 |
+
if (!$term && (!isset($args['fields']) || !$args['fields']) && (!isset($args['extra']) || !$args['extra']) )
|
546 |
+
return array();
|
547 |
+
|
548 |
+
$query = "SELECT DISTINCT ID FROM {$wpdb->posts}";
|
549 |
+
$where = $wpdb->prepare("{$wpdb->posts}.post_type = %s AND {$wpdb->posts}.post_status = %s",
|
550 |
+
WPBDP_POST_TYPE, 'publish');
|
551 |
+
|
552 |
+
if ($term) {
|
553 |
+
// process term
|
554 |
+
$where .= $wpdb->prepare(" AND ({$wpdb->posts}.post_title LIKE '%%%s%%' OR {$wpdb->posts}.post_content LIKE '%%%s%%' OR {$wpdb->posts}.post_excerpt LIKE '%%%s%%')", $term, $term, $term);
|
555 |
+
}
|
556 |
+
|
557 |
+
if (isset($args['fields'])) {
|
558 |
+
foreach ($args['fields'] as $i => $meta_search) {
|
559 |
+
|
560 |
+
if ( $field = wpbdp_get_formfield( $meta_search['field_id'] ) ) {
|
561 |
+
$q = is_array( $meta_search['q'] ) ? array_map( 'trim', $meta_search['q'] ) : trim( $meta_search['q'] );
|
562 |
+
|
563 |
+
if (!$q) continue;
|
564 |
+
|
565 |
+
switch ( $field->get_association() ) {
|
566 |
+
case 'title':
|
567 |
+
$where .= $wpdb->prepare(" AND {$wpdb->posts}.post_title LIKE '%%%s%%'", $q);
|
568 |
+
break;
|
569 |
+
case 'content':
|
570 |
+
$where .= $wpdb->prepare(" AND {$wpdb->posts}.post_content LIKE '%%%s%%'", $q);
|
571 |
+
break;
|
572 |
+
case 'excerpt':
|
573 |
+
$where .= $wpdb->prepare(" AND {$wpdb->posts}.post_excerpt LIKE '%%%s%%'", $q);
|
574 |
+
break;
|
575 |
+
case 'category':
|
576 |
+
$term_ids = array_diff( is_array($q) ? $q : array($q), array('-1', '0') ) ;
|
577 |
+
$terms = array();
|
578 |
+
|
579 |
+
// $term_ids = implode(',', array_diff($term_ids, array('-1', '0')) );
|
580 |
+
|
581 |
+
foreach ( $term_ids as $tid ) {
|
582 |
+
$terms[] = $tid;
|
583 |
+
$terms = array_merge( $terms, get_term_children( $tid, WPBDP_CATEGORY_TAX ) );
|
584 |
+
}
|
585 |
+
|
586 |
+
if ($terms) {
|
587 |
+
$query .= " LEFT JOIN {$wpdb->term_relationships} AS trel1 ON ({$wpdb->posts}.ID = trel1.object_id) LEFT JOIN {$wpdb->term_taxonomy} AS ttax1 ON (trel1.term_taxonomy_id = ttax1.term_taxonomy_id)";
|
588 |
+
$where .= " AND ttax1.term_id IN (" . implode( ',', $terms ) . ") ";
|
589 |
+
}
|
590 |
+
|
591 |
+
break;
|
592 |
+
case 'tags':
|
593 |
+
$terms = is_array($q) ? array_values($q) : explode(',', $q);
|
594 |
+
$term_ids = array();
|
595 |
+
|
596 |
+
foreach ($terms as $term_name) {
|
597 |
+
$term = null;
|
598 |
+
|
599 |
+
if ( $term_name === '-1' || $term_name === '0' )
|
600 |
+
continue;
|
601 |
+
|
602 |
+
// if ( is_numeric( $term_name ) )
|
603 |
+
// $term = get_term_by( 'id', $term_name, WPBDP_TAGS_TAX );
|
604 |
+
|
605 |
+
// if ( !$term )
|
606 |
+
if ( strpos( $term_name, '&' ) !== false )
|
607 |
+
$term_name = htmlentities( $term_name, null, null, false );
|
608 |
+
|
609 |
+
$term = get_term_by( 'name', $term_name, WPBDP_TAGS_TAX );
|
610 |
+
|
611 |
+
if ( $term ) {
|
612 |
+
$term_ids[] = $term->term_id;
|
613 |
+
} else {
|
614 |
+
$where .= ' AND 1=0'; // force no results when a tag does not exist
|
615 |
+
}
|
616 |
+
}
|
617 |
+
|
618 |
+
if ($term_ids) {
|
619 |
+
$term_ids = implode(',', $term_ids);
|
620 |
+
$query .= " LEFT JOIN {$wpdb->term_relationships} AS trel2 ON ({$wpdb->posts}.ID = trel2.object_id) LEFT JOIN {$wpdb->term_taxonomy} AS ttax2 ON (trel2.term_taxonomy_id = ttax2.term_taxonomy_id)";
|
621 |
+
$where .= " AND ttax2.term_id IN ({$term_ids}) ";
|
622 |
+
}
|
623 |
+
|
624 |
+
break;
|
625 |
+
case 'meta':
|
626 |
+
// Multi-valued field.
|
627 |
+
if (in_array($field->get_field_type()->get_id(), array('checkbox', 'multiselect', 'select'))) {
|
628 |
+
$options = array_diff( is_array( $q ) ? $q : array( $q ), array( '-1' ) );
|
629 |
+
$options = array_map( 'preg_quote', $options );
|
630 |
+
|
631 |
+
if (!$options)
|
632 |
+
continue;
|
633 |
+
|
634 |
+
$pattern = '(' . implode('|', $options) . '){1}([tab]{0,1})';
|
635 |
+
|
636 |
+
$query .= " INNER JOIN {$wpdb->postmeta} AS mt{$i}mv ON ({$wpdb->posts}.ID = mt{$i}mv.post_id)";
|
637 |
+
$where .= $wpdb->prepare(" AND (mt{$i}mv.meta_key = %s AND mt{$i}mv.meta_value REGEXP %s )",
|
638 |
+
"_wpbdp[fields][" . $field->get_id() . "]",
|
639 |
+
$pattern );
|
640 |
+
} else { // Single-valued field.
|
641 |
+
if ( in_array( $field->get_field_type()->get_id(),
|
642 |
+
array( 'textfield', 'textarea' ) ) ) {
|
643 |
+
$query .= sprintf(" INNER JOIN {$wpdb->postmeta} AS mt%1$1d ON ({$wpdb->posts}.ID = mt%1$1d.post_id)", $i);
|
644 |
+
$where .= $wpdb->prepare(" AND (mt{$i}.meta_key = %s AND mt{$i}.meta_value LIKE '%%%s%%')",
|
645 |
+
'_wpbdp[fields][' . $field->get_id() . ']',
|
646 |
+
$q);
|
647 |
+
} else {
|
648 |
+
$query .= sprintf(" INNER JOIN {$wpdb->postmeta} AS mt%1$1d ON ({$wpdb->posts}.ID = mt%1$1d.post_id)", $i);
|
649 |
+
$where .= $wpdb->prepare(" AND (mt{$i}.meta_key = %s AND mt{$i}.meta_value = %s)",
|
650 |
+
'_wpbdp[fields][' . $field->get_id() . ']',
|
651 |
+
$q);
|
652 |
+
}
|
653 |
+
}
|
654 |
+
|
655 |
+
break;
|
656 |
+
default:
|
657 |
+
break;
|
658 |
+
}
|
659 |
+
}
|
660 |
+
|
661 |
+
}
|
662 |
+
}
|
663 |
+
|
664 |
+
$query .= ' WHERE ' . apply_filters('wpbdp_search_where', $where, $args);
|
665 |
+
$query = apply_filters( 'wpbdp_search_query ', $query, $args );
|
666 |
+
|
667 |
+
return $wpdb->get_col($query);
|
668 |
+
}
|
669 |
+
|
670 |
+
public function send_renewal_email( $renewal_id, $email_message_type = 'auto' ) {
|
671 |
+
global $wpdb;
|
672 |
+
|
673 |
+
$renewal_id = intval( $renewal_id );
|
674 |
+
$fee_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", $renewal_id ) );
|
675 |
+
|
676 |
+
if ( !$fee_info || !$fee_info->expires_on )
|
677 |
+
return false;
|
678 |
+
|
679 |
+
|
680 |
+
$message_option = '';
|
681 |
+
|
682 |
+
if ( $email_message_type == 'auto' ) {
|
683 |
+
$expiration = strtotime( $fee_info->expires_on );
|
684 |
+
$current_time = time();
|
685 |
+
|
686 |
+
if ( $expiration > $current_time ) {
|
687 |
+
$message_option = 'renewal-pending-message';
|
688 |
+
} else {
|
689 |
+
$message_option = 'listing-renewal-message';
|
690 |
+
}
|
691 |
+
} elseif ( $email_message_type ) {
|
692 |
+
$message_option = $email_message_type;
|
693 |
+
} else {
|
694 |
+
$message_option = 'listing-renewal-message';
|
695 |
+
}
|
696 |
+
|
697 |
+
$listing = WPBDP_Listing::get( $fee_info->listing_id );
|
698 |
+
|
699 |
+
$renewal_url = $listing->get_renewal_url( $fee_info->category_id );
|
700 |
+
$message_replacements = array( 'site' => sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'name' ) ),
|
701 |
+
'listing' => esc_attr( get_the_title( $fee_info->listing_id ) ),
|
702 |
+
'category' => get_term( $fee_info->category_id, WPBDP_CATEGORY_TAX )->name,
|
703 |
+
'expiration' => date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $fee_info->expires_on ) ),
|
704 |
+
'link' => sprintf( '<a href="%1$s">%1$s</a>', $renewal_url )
|
705 |
+
);
|
706 |
+
|
707 |
+
$email = wpbdp_email_from_template( $message_option, $message_replacements );
|
708 |
+
$email->to[] = wpbusdirman_get_the_business_email( $fee_info->listing_id );
|
709 |
+
$email->send();
|
710 |
+
|
711 |
+
return true;
|
712 |
+
}
|
713 |
+
|
714 |
+
|
715 |
+
/**
|
716 |
+
* Notifies listings expiring soon. Despite its name this function also changes listings according to expiration rules (removing categories, unpublishing, etc.).
|
717 |
+
* @param int $threshold A threshold (in days) to use for checking listing expiration times: 0 means already expired listings and a positive
|
718 |
+
* value checks listings expiring between now and now + $threshold.
|
719 |
+
* @param int $now Timestamp to use as current time. Defaults to the value of `current_time( 'timestamp' )`.
|
720 |
+
* @since 3.1
|
721 |
+
*/
|
722 |
+
public function notify_expiring_listings( $threshold=0, $now=null ) {
|
723 |
+
global $wpdb;
|
724 |
+
|
725 |
+
$threshold = intval( $threshold );
|
726 |
+
$now = $now > 0 ? intval( $now ) : current_time( 'timestamp' );
|
727 |
+
|
728 |
+
$query = '';
|
729 |
+
$now_date = wpbdp_format_time( $now, 'mysql' );
|
730 |
+
|
731 |
+
if ( $threshold == 0 ) {
|
732 |
+
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE recurring = %d AND expires_on IS NOT NULL AND expires_on < %s AND email_sent <> %d AND email_sent <> %d ORDER BY expires_on LIMIT 100",
|
733 |
+
0,
|
734 |
+
$now_date,
|
735 |
+
2,
|
736 |
+
3 );
|
737 |
+
} else {
|
738 |
+
if ( $threshold > 0 ) {
|
739 |
+
$end_date = wpbdp_format_time( strtotime( sprintf( '+%d days', $threshold ), $now ), 'mysql' );
|
740 |
+
|
741 |
+
if ( wpbdp_get_option( 'send-autorenewal-expiration-notice' ) ) {
|
742 |
+
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE expires_on IS NOT NULL AND expires_on >= %s AND expires_on <= %s AND email_sent = %d ORDER BY expires_on LIMIT 100",
|
743 |
+
$now_date,
|
744 |
+
$end_date,
|
745 |
+
0 );
|
746 |
+
} else {
|
747 |
+
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE recurring = %d AND expires_on IS NOT NULL AND expires_on >= %s AND expires_on <= %s AND email_sent = %d ORDER BY expires_on LIMIT 100",
|
748 |
+
0,
|
749 |
+
$now_date,
|
750 |
+
$end_date,
|
751 |
+
0 );
|
752 |
+
}
|
753 |
+
} else {
|
754 |
+
$exp_date = wpbdp_format_time( strtotime( sprintf( '%d days', $threshold ), $now ), 'mysql' );
|
755 |
+
|
756 |
+
$query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE recurring = %d AND expires_on IS NOT NULL AND expires_on < %s AND email_sent = %d",
|
757 |
+
0,
|
758 |
+
$exp_date,
|
759 |
+
2 );
|
760 |
+
}
|
761 |
+
}
|
762 |
+
|
763 |
+
$rs = $wpdb->get_results( $query );
|
764 |
+
|
765 |
+
if ( !$rs )
|
766 |
+
return;
|
767 |
+
|
768 |
+
foreach ( $rs as &$r ) {
|
769 |
+
$listing = WPBDP_Listing::get( $r->listing_id );
|
770 |
+
|
771 |
+
if ( ! $listing )
|
772 |
+
continue;
|
773 |
+
|
774 |
+
$base_replacements = array( 'site' => sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'name' ) ),
|
775 |
+
'author' => get_the_author_meta( 'display_name', get_post( $r->listing_id )->post_author ),
|
776 |
+
'listing' => sprintf( '<a href="%s">%s</a>', $listing->get_permalink(), esc_attr( $listing->get_title() ) ),
|
777 |
+
'category' => wpbdp_get_term_name( $r->category_id ),
|
778 |
+
'expiration' => date_i18n( get_option( 'date_format' ), strtotime( $r->expires_on ) )
|
779 |
+
);
|
780 |
+
|
781 |
+
if ( ! $r->recurring ) {
|
782 |
+
$renewal_url = $listing->get_renewal_url( $r->category_id );
|
783 |
+
$message_replacements = array_merge( $base_replacements, array(
|
784 |
+
'link' => sprintf( '<a href="%1$s">%1$s</a>', $renewal_url )
|
785 |
+
) );
|
786 |
+
} else {
|
787 |
+
$message_replacements = array_merge( $base_replacements, array(
|
788 |
+
'date' => $base_replacements['expiration'],
|
789 |
+
'link' => sprintf( '<a href="%1$s">%1$s</a>', add_query_arg( 'action', 'manage-recurring', wpbdp_get_page_link( 'main' ) ) )
|
790 |
+
) );
|
791 |
+
}
|
792 |
+
|
793 |
+
if ( 0 == $threshold ) {
|
794 |
+
// handle expired listings
|
795 |
+
|
796 |
+
// remove expired category from post
|
797 |
+
$listing->remove_category( $r->category_id, false );
|
798 |
+
|
799 |
+
if ( ! $listing->get_categories( 'current' ) ) {
|
800 |
+
// $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d", wpbdp_get_option( 'deleted-status' ), $r->listing_id ) );
|
801 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d", 'draft', $listing->get_id() ) );
|
802 |
+
}
|
803 |
+
|
804 |
+
$email = wpbdp_email_from_template( 'listing-renewal-message', $message_replacements );
|
805 |
+
$email->to[] = wpbusdirman_get_the_business_email( $listing->get_id() );
|
806 |
+
|
807 |
+
if ( in_array( 'renewal', wpbdp_get_option( 'admin-notifications' ), true ) ) {
|
808 |
+
$email->cc[] = get_option( 'admin_email' );
|
809 |
+
|
810 |
+
if ( wpbdp_get_option( 'admin-notifications-cc' ) )
|
811 |
+
$email->cc[] = wpbdp_get_option( 'admin-notifications-cc' );
|
812 |
+
}
|
813 |
+
|
814 |
+
$email->send();
|
815 |
+
|
816 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_listing_fees", array( 'email_sent' => 2 ), array( 'id' => $r->id ) );
|
817 |
+
} elseif ( $threshold > 0 ) {
|
818 |
+
// notify about coming expirations
|
819 |
+
$email = wpbdp_email_from_template( ( $r->recurring ? 'listing-autorenewal-notice' : 'renewal-pending-message' ),
|
820 |
+
$message_replacements );
|
821 |
+
$email->to[] = wpbusdirman_get_the_business_email( $listing->get_id() );
|
822 |
+
$email->send();
|
823 |
+
|
824 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_listing_fees", array( 'email_sent' => 1 ), array( 'id' => $r->id ) );
|
825 |
+
} elseif ( $threshold < 0 ) {
|
826 |
+
// remind about expired listings
|
827 |
+
$email = wpbdp_email_from_template( 'renewal-reminder-message', $message_replacements );
|
828 |
+
$email->to[] = wpbusdirman_get_the_business_email( $listing->get_id() );
|
829 |
+
$email->send();
|
830 |
+
|
831 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_listing_fees", array( 'email_sent' => 3 ), array( 'id' => $r->id ) );
|
832 |
+
}
|
833 |
+
}
|
834 |
+
|
835 |
+
}
|
836 |
+
|
837 |
+
}
|
838 |
+
|
839 |
+
/*
|
840 |
+
* For compatibility with other APIs (< 3.5.4).
|
841 |
+
*/
|
842 |
+
class WPBDP_ListingsAPI extends WPBDP_Listings_API {}
|
843 |
+
|
844 |
+
}
|
core/class-listings-widget.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @since 3.5.3
|
4 |
+
*/
|
5 |
+
class WPBDP_Listings_Widget extends WP_Widget {
|
6 |
+
|
7 |
+
protected $supports = array( 'images' );
|
8 |
+
protected $defaults = array();
|
9 |
+
|
10 |
+
|
11 |
+
public function __construct( $name, $description = '' ) {
|
12 |
+
parent::__construct( false, $name, array( 'description' => $description ) );
|
13 |
+
|
14 |
+
$this->defaults['title'] = str_replace( array( 'WPBDP', '_' ), array( '', ' '), get_class( $this ) );
|
15 |
+
$this->defaults['number_of_listings'] = 10;
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function set_default_option_value( $k, $v = '' ) {
|
19 |
+
$this->defaults[ $k ] = $v;
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function get_field_value( $instance, $k ) {
|
23 |
+
if ( isset( $instance[ $k ] ) )
|
24 |
+
return $instance[ $k ];
|
25 |
+
|
26 |
+
if ( isset( $this->defaults[ $k ] ) )
|
27 |
+
return $this->defaults[ $k ];
|
28 |
+
|
29 |
+
return false;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function print_listings( $instance ) {
|
33 |
+
return '';
|
34 |
+
}
|
35 |
+
|
36 |
+
public function get_listings( $instance ) {
|
37 |
+
return array();
|
38 |
+
}
|
39 |
+
|
40 |
+
protected function _form( $instance ) { }
|
41 |
+
|
42 |
+
public function form( $instance ) {
|
43 |
+
printf( '<p><label for="%s">%s</label> <input class="widefat" id="%s" name="%s" type="text" value="%s" /></p>',
|
44 |
+
$this->get_field_id( 'title' ),
|
45 |
+
_x( 'Title:', 'widgets', 'WPBDM' ),
|
46 |
+
$this->get_field_id( 'title' ),
|
47 |
+
$this->get_field_name( 'title' ),
|
48 |
+
esc_attr( $this->get_field_value( $instance, 'title' ) ) );
|
49 |
+
printf( '<p><label for="%s">%s</label> <input id="%s" name="%s" type="text" value="%s" size="5" /></p>',
|
50 |
+
$this->get_field_id( 'number_of_listings' ),
|
51 |
+
_x( 'Number of listings to display:', 'widgets', 'WPBDM' ),
|
52 |
+
$this->get_field_id( 'number_of_listings' ),
|
53 |
+
$this->get_field_name( 'number_of_listings' ),
|
54 |
+
intval( $this->get_field_value( $instance, 'number_of_listings' ) ) );
|
55 |
+
|
56 |
+
$this->_form( $instance );
|
57 |
+
|
58 |
+
if ( in_array( 'images', $this->supports ) ) {
|
59 |
+
echo '<h4>';
|
60 |
+
_ex( 'Thumbnails', 'widgets', 'WPBDM' );
|
61 |
+
echo '</h4>';
|
62 |
+
|
63 |
+
printf( '<p><input id="%s" class="wpbdp-toggle-images" name="%s" type="checkbox" value="1" %s /> <label for="%s">%s</label></p>',
|
64 |
+
$this->get_field_id( 'show_images' ),
|
65 |
+
$this->get_field_name( 'show_images' ),
|
66 |
+
$this->get_field_value( $instance, 'show_images' ) ? 'checked="checked"' : '',
|
67 |
+
$this->get_field_id( 'show_images' ),
|
68 |
+
_x( 'Show thumbnails', 'widgets', 'WPBDM' ) );
|
69 |
+
|
70 |
+
echo '<p class="thumbnail-width-config" style="' . ( $this->get_field_value( $instance, 'show_images' ) ? '' : 'display: none;' ) . '">';
|
71 |
+
echo '<label for="' . $this->get_field_id( 'thumbnail_width' ) . '">';
|
72 |
+
_ex( 'Image width (in px):', 'widgets', 'WPBDM' );
|
73 |
+
echo '</label> ';
|
74 |
+
printf( '<input type="text" name="%s" id="%s" value="%s" size="5" />',
|
75 |
+
$this->get_field_name( 'thumbnail_width' ),
|
76 |
+
$this->get_field_id( 'thumbnail_width' ),
|
77 |
+
$this->get_field_value( $instance, 'thumbnail_width' ) );
|
78 |
+
echo '<br /><span class="help">' . _x( 'Leave blank for automatic width.', 'widgets', 'WPBDM' ) . '</span>';
|
79 |
+
echo '</p>';
|
80 |
+
|
81 |
+
echo '<p class="thumbnail-height-config" style="' . ( $this->get_field_value( $instance, 'show_images' ) ? '' : 'display: none;' ) . '">';
|
82 |
+
echo '<label for="' . $this->get_field_id( 'thumbnail_height' ) . '">';
|
83 |
+
_ex( 'Image height (in px):', 'widgets', 'WPBDM' );
|
84 |
+
echo '</label> ';
|
85 |
+
printf( '<input type="text" name="%s" id="%s" value="%s" size="5" />',
|
86 |
+
$this->get_field_name( 'thumbnail_height' ),
|
87 |
+
$this->get_field_id( 'thumbnail_height' ),
|
88 |
+
$this->get_field_value( $instance, 'thumbnail_height' ) );
|
89 |
+
echo '<br /><span class="help">' . _x( 'Leave blank for automatic height.', 'widgets', 'WPBDM' ) . '</span>';
|
90 |
+
echo '</p>';
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
public function update( $new, $old ) {
|
95 |
+
$new['title'] = strip_tags( $new['title'] );
|
96 |
+
$new['number_of_listings'] = max( intval( $new['number_of_listings'] ), 1 );
|
97 |
+
$new['show_images'] = intval( $new['show_images'] ) == 1 ? 1 : 0;
|
98 |
+
|
99 |
+
if ( $new['show_images'] ) {
|
100 |
+
$new['thumbnail_width'] = max( intval( $new['thumbnail_width'] ), 0 );
|
101 |
+
$new['thumbnail_height'] = max( intval( $new['thumbnail_height'] ), 0 );
|
102 |
+
}
|
103 |
+
|
104 |
+
return $new;
|
105 |
+
}
|
106 |
+
|
107 |
+
public function widget( $args, $instance ) {
|
108 |
+
extract($args);
|
109 |
+
$title = apply_filters( 'widget_title', $instance['title'] );
|
110 |
+
|
111 |
+
echo $before_widget;
|
112 |
+
if ( ! empty( $title ) )
|
113 |
+
echo $before_title . $title . $after_title;
|
114 |
+
|
115 |
+
$out = $this->print_listings( $instance );
|
116 |
+
|
117 |
+
if ( ! $out ) {
|
118 |
+
if ( $listings = $this->get_listings( $instance ) ) {
|
119 |
+
$show_images = in_array( 'images', $this->supports ) && isset( $instance['show_images'] ) && $instance['show_images'];
|
120 |
+
$thumb_w = isset( $instance['thumbnail_width'] ) ? $instance['thumbnail_width'] : 0;
|
121 |
+
$thumb_h = isset( $instance['thumbnail_height'] ) ? $instance['thumbnail_height'] : 0;
|
122 |
+
|
123 |
+
$img_size = 'wpbdp-thumb';
|
124 |
+
if ( $show_images && ( $thumb_w > 0 || $thumb_h > 0 ) ) {
|
125 |
+
$img_size = array( $thumb_w, $thumb_h );
|
126 |
+
}
|
127 |
+
|
128 |
+
$out .= '<ul class="wpbdp-listings-widget-list">';
|
129 |
+
|
130 |
+
foreach ( $listings as &$post ) {
|
131 |
+
$listing = WPBDP_Listing::get( $post->ID );
|
132 |
+
|
133 |
+
$out .= '<li>';
|
134 |
+
$out .= sprintf( '<a class="listing-title" href="%s">%s</a>', get_permalink( $post->ID ), get_the_title( $post->ID ) );
|
135 |
+
|
136 |
+
if ( $show_images ) {
|
137 |
+
if ( $img_id = $listing->get_thumbnail_id() ) {
|
138 |
+
$out .= '<a href="' . get_permalink( $post->ID ) . '">' . wp_get_attachment_image( $img_id, $img_size, false, array( 'class' => 'listing-image' ) ) . '</a>';
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
$out .= '</li>';
|
143 |
+
}
|
144 |
+
|
145 |
+
$out .= '</ul>';
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
echo $out;
|
150 |
+
echo $after_widget;
|
151 |
+
}
|
152 |
+
|
153 |
+
}
|
core/class-page-meta.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// TODO: we need to disable the date filters after a moment to not affect everything (when?).
|
4 |
+
class WPBDP_Page_Meta {
|
5 |
+
|
6 |
+
private $action = '';
|
7 |
+
private $listing_id = 0;
|
8 |
+
|
9 |
+
public function __construct( $action = '' ) {
|
10 |
+
$this->action = $action;
|
11 |
+
|
12 |
+
if ( 'showlisting' == $this->action ) {
|
13 |
+
$this->listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
|
14 |
+
|
15 |
+
add_filter( 'get_the_time', array( &$this, 'listing_page__get_the_time' ), 10, 2 );
|
16 |
+
add_filter( 'get_the_date', array( &$this, 'listing_page__get_the_date' ), 10, 2 );
|
17 |
+
add_filter( 'get_the_modified_time', array( &$this, 'listing_page__get_the_modified_time' ), 10, 2 );
|
18 |
+
add_filter( 'get_the_modified_date', array( &$this, 'listing_page__get_the_modified_date' ), 10, 2 );
|
19 |
+
}
|
20 |
+
}
|
21 |
+
|
22 |
+
// {{ Listing view.
|
23 |
+
|
24 |
+
public function listing_page__get_the_time( $the_time, $d = '' ) {
|
25 |
+
if ( ! $this->listing_id )
|
26 |
+
return $the_time;
|
27 |
+
|
28 |
+
if ( ! $d )
|
29 |
+
$d = get_option( 'time_format' );
|
30 |
+
|
31 |
+
//remove_filter( 'get_the_time', array( &$this, 'listing_page__get_the_time' ), 10, 2 );
|
32 |
+
return get_post_time( $d, false, $this->listing_id, true );
|
33 |
+
}
|
34 |
+
|
35 |
+
public function listing_page__get_the_date( $the_date, $d = '' ) {
|
36 |
+
if ( ! $this->listing_id )
|
37 |
+
return $the_date;
|
38 |
+
|
39 |
+
if ( ! $d )
|
40 |
+
$d = get_option( 'date_format' );
|
41 |
+
|
42 |
+
//remove_filter( 'get_the_date', array( &$this, 'listing_page__get_the_date' ), 10, 2 );
|
43 |
+
return get_post_time( $d, $this->listing_id );
|
44 |
+
}
|
45 |
+
|
46 |
+
public function listing_page__get_the_modified_time( $the_time, $d = '' ) {
|
47 |
+
if ( ! $this->listing_id )
|
48 |
+
return $the_time;
|
49 |
+
|
50 |
+
if ( ! $d )
|
51 |
+
$d = get_option( 'time_format' );
|
52 |
+
|
53 |
+
//remove_filter( 'get_the_modified_time', array( &$this, 'listing_page__get_the_modified_time' ), 10, 2 );
|
54 |
+
return get_post_modified_time( $d, false, $this->listing_id, true );
|
55 |
+
}
|
56 |
+
|
57 |
+
public function listing_page__get_the_modified_date( $the_date, $d = '' ) {
|
58 |
+
if ( ! $this->listing_id )
|
59 |
+
return $the_date;
|
60 |
+
|
61 |
+
if ( ! $d )
|
62 |
+
$d = get_option( 'date_format' );
|
63 |
+
|
64 |
+
//remove_filter( 'get_the_modified_date', array( &$this, 'listing_page__get_the_modified_date' ), 10, 2 );
|
65 |
+
return get_post_modified_time( $d, false, $this->listing_id, true );
|
66 |
+
}
|
67 |
+
|
68 |
+
// }}
|
69 |
+
|
70 |
+
}
|
core/class-payment.php
ADDED
@@ -0,0 +1,430 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-db-model.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* This class represents a listing payment.
|
6 |
+
*
|
7 |
+
* @since 3.3
|
8 |
+
*/
|
9 |
+
class WPBDP_Payment extends WPBDP_DB_Model {
|
10 |
+
|
11 |
+
const STATUS_UNKNOWN = 'unknown';
|
12 |
+
const STATUS_NEW = 'new';
|
13 |
+
const STATUS_PENDING = 'pending';
|
14 |
+
const STATUS_COMPLETED = 'completed';
|
15 |
+
const STATUS_CANCELED = 'canceled';
|
16 |
+
const STATUS_REJECTED = 'rejected';
|
17 |
+
|
18 |
+
const HANDLER_GATEWAY = 'gateway';
|
19 |
+
const HANDLER_ADMIN = 'admin';
|
20 |
+
const HANDLER_SYSTEM = 'system';
|
21 |
+
|
22 |
+
private $items = array();
|
23 |
+
|
24 |
+
public function __construct( $data = array() ) {
|
25 |
+
$this->fill_from_data( $data, array(
|
26 |
+
'id' => 0,
|
27 |
+
'listing_id' => 0,
|
28 |
+
'gateway' => '',
|
29 |
+
'currency_code' => wpbdp_get_option( 'currency' ),
|
30 |
+
'amount' => 0.0,
|
31 |
+
'status' => self::STATUS_PENDING,
|
32 |
+
'created_on' => current_time( 'mysql' ),
|
33 |
+
'processed_on' => '',
|
34 |
+
'processed_by' => '',
|
35 |
+
'payerinfo' => array(),
|
36 |
+
'extra_data' => array(),
|
37 |
+
'notes' => array()
|
38 |
+
) );
|
39 |
+
|
40 |
+
$this->amount = floatval( $this->amount );
|
41 |
+
|
42 |
+
global $wpdb;
|
43 |
+
|
44 |
+
if ( $this->id > 0 ) {
|
45 |
+
foreach ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_payments_items WHERE payment_id = %d", $this->id ), ARRAY_A ) as $item ) {
|
46 |
+
$item['data'] = maybe_unserialize( $item['data'] );
|
47 |
+
$this->items[] = $item;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
public function reset() {
|
53 |
+
$this->gateway = '';
|
54 |
+
$this->processed_by = '';
|
55 |
+
$this->processed_on = '';
|
56 |
+
$this->payerinfo = array();
|
57 |
+
$this->status = self::STATUS_PENDING;
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
// TODO: when a payment is saved (and it's completed) all payments it superseeds should be removed/rejected (i.e. a payment for the same category or an already pending upgrade)
|
62 |
+
public function save() {
|
63 |
+
global $wpdb;
|
64 |
+
|
65 |
+
// do_action_ref_array( 'WPBDP_Payment::before_save', array( &$this ) );
|
66 |
+
|
67 |
+
$row = array(
|
68 |
+
'listing_id' => $this->listing_id,
|
69 |
+
'gateway' => $this->gateway,
|
70 |
+
'amount' => $this->amount,
|
71 |
+
'status' => $this->status,
|
72 |
+
'created_on' => $this->created_on,
|
73 |
+
'processed_on' => $this->processed_on,
|
74 |
+
'processed_by' => $this->processed_by,
|
75 |
+
'currency_code' => $this->currency_code,
|
76 |
+
'payerinfo' => serialize( is_array( $this->payerinfo ) ? $this->payerinfo : array() ),
|
77 |
+
'extra_data' => serialize( is_array( $this->extra_data ) ? $this->extra_data : array() ),
|
78 |
+
'notes' => serialize( is_array( $this->notes ) ? $this->notes : array() )
|
79 |
+
);
|
80 |
+
|
81 |
+
if ( $this->id )
|
82 |
+
$row['id'] = $this->id;
|
83 |
+
|
84 |
+
if ( false === $wpdb->replace( $wpdb->prefix . 'wpbdp_payments', $row ) )
|
85 |
+
return false;
|
86 |
+
|
87 |
+
$this->id = $this->id ? $this->id : $wpdb->insert_id;
|
88 |
+
|
89 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments_items WHERE payment_id = %d", $this->id ) );
|
90 |
+
|
91 |
+
foreach ( $this->items as &$item ) {
|
92 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_payments_items',
|
93 |
+
array( 'item_type' => $item['item_type'],
|
94 |
+
'amount' => $item['amount'],
|
95 |
+
'description' => $item['description'],
|
96 |
+
'payment_id' => $this->id,
|
97 |
+
'rel_id_1' => $item['rel_id_1'],
|
98 |
+
'rel_id_2' => $item['rel_id_2'],
|
99 |
+
'data' => serialize( $item['data'] ) )
|
100 |
+
);
|
101 |
+
}
|
102 |
+
|
103 |
+
do_action_ref_array( 'WPBDP_Payment::save', array( &$this ) );
|
104 |
+
|
105 |
+
if ( $this->status != self::STATUS_COMPLETED && $this->amount == 0.0 ) {
|
106 |
+
$this->set_status( self::STATUS_COMPLETED );
|
107 |
+
$this->save();
|
108 |
+
}
|
109 |
+
|
110 |
+
return true;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function delete() {
|
114 |
+
}
|
115 |
+
|
116 |
+
public function is_payment_due() {
|
117 |
+
return $this->amount > 0.0 && $this->status != self::STATUS_COMPLETED;
|
118 |
+
}
|
119 |
+
|
120 |
+
public function is_pending() {
|
121 |
+
return $this->status == self::STATUS_PENDING;
|
122 |
+
}
|
123 |
+
|
124 |
+
public function is_completed() {
|
125 |
+
return $this->status == self::STATUS_COMPLETED;
|
126 |
+
}
|
127 |
+
|
128 |
+
public function is_canceled() {
|
129 |
+
return $this->status == self::STATUS_CANCELED;
|
130 |
+
}
|
131 |
+
|
132 |
+
public function is_rejected() {
|
133 |
+
return $this->status == self::STATUS_REJECTED;
|
134 |
+
}
|
135 |
+
|
136 |
+
public function has_been_processed() {
|
137 |
+
return ! empty( $this->processed_by );
|
138 |
+
}
|
139 |
+
|
140 |
+
public function is_first_recurring_payment() {
|
141 |
+
return $this->has_item_type( 'recurring_fee' ) && ( ! $this->get_data( 'recurring_id' ) );
|
142 |
+
}
|
143 |
+
|
144 |
+
public function generate_recurring_payment() {
|
145 |
+
$recurring_item = $this->get_recurring_item();
|
146 |
+
|
147 |
+
if ( ! $recurring_item )
|
148 |
+
return null;
|
149 |
+
|
150 |
+
$rp = new WPBDP_Payment( array( 'listing_id' => $this->get_listing_id(),
|
151 |
+
'gateway' => $this->get_gateway(),
|
152 |
+
'currency_code' => $this->get_currency_code(),
|
153 |
+
'amount' => 0.0,
|
154 |
+
'payerinfo' => $this->payerinfo,
|
155 |
+
'extra_data' => array( 'recurring_id' => $this->get_data( 'recurring_id' ),
|
156 |
+
'parent_payment_id' => $this->id )
|
157 |
+
) );
|
158 |
+
$rp->add_item( 'recurring_fee',
|
159 |
+
$recurring_item->amount,
|
160 |
+
$recurring_item->description,
|
161 |
+
$recurring_item->data,
|
162 |
+
$recurring_item->rel_id_1,
|
163 |
+
$recurring_item->rel_id_2 );
|
164 |
+
$rp->save();
|
165 |
+
return $rp;
|
166 |
+
}
|
167 |
+
|
168 |
+
public function get_handler() {
|
169 |
+
return $this->processed_by;
|
170 |
+
}
|
171 |
+
|
172 |
+
public function get_processed_on() {
|
173 |
+
return $this->processed_on;
|
174 |
+
}
|
175 |
+
|
176 |
+
public function cancel_recurring() {
|
177 |
+
if ( ! $this->id )
|
178 |
+
return;
|
179 |
+
|
180 |
+
$listing = WPBDP_Listing::get( $this->get_listing_id() );
|
181 |
+
$recurring_item = $this->get_recurring_item();
|
182 |
+
|
183 |
+
if ( $recurring_item )
|
184 |
+
$listing->remove_category( $recurring_item->rel_id_1 );
|
185 |
+
}
|
186 |
+
|
187 |
+
public function get_recurring_item() {
|
188 |
+
$items = $this->get_items( array( 'item_type' => 'recurring_fee' ) );
|
189 |
+
return $items ? $items[0] : null;
|
190 |
+
}
|
191 |
+
|
192 |
+
public function add_item( $item_type = 'charge', $amount = 0.0, $description = '', $data = array(), $rel_id_1 = 0, $rel_id_2 = 0 ) {
|
193 |
+
$item = array();
|
194 |
+
$item['item_type'] = $item_type;
|
195 |
+
$item['amount'] = floatval( $amount );
|
196 |
+
$item['description'] = $description;
|
197 |
+
$item['data'] = $data;
|
198 |
+
|
199 |
+
$item['rel_id_1'] = $rel_id_1;
|
200 |
+
$item['rel_id_2'] = $rel_id_2;
|
201 |
+
|
202 |
+
$this->items[] = $item;
|
203 |
+
$this->amount += $amount;
|
204 |
+
}
|
205 |
+
|
206 |
+
public function add_category_fee_item( $category_id, $fee ) {
|
207 |
+
if ( is_int( $fee ) ) {
|
208 |
+
$fee = wpbdp_get_fee( $fee );
|
209 |
+
|
210 |
+
if ( ! $fee )
|
211 |
+
return false;
|
212 |
+
}
|
213 |
+
|
214 |
+
$this->add_item( 'fee',
|
215 |
+
$fee->amount,
|
216 |
+
sprintf( _x( 'Fee "%s" for category "%s"', 'listings', 'WPBDM' ),
|
217 |
+
$fee->label,
|
218 |
+
wpbdp_get_term_name( $category_id ) ),
|
219 |
+
array( 'fee_id' => $fee->id, 'fee_days' => $fee->days, 'fee_images' => $fee->images ),
|
220 |
+
$category_id,
|
221 |
+
$fee->id );
|
222 |
+
return true;
|
223 |
+
}
|
224 |
+
|
225 |
+
public function update_items( $items = array() ) {
|
226 |
+
$this->amount = 0.0;
|
227 |
+
$this->items = array();
|
228 |
+
|
229 |
+
foreach ( $items as $item ) {
|
230 |
+
$item = (array) $item;
|
231 |
+
$this->items[] = $item;
|
232 |
+
$this->amount += $item['amount'];
|
233 |
+
}
|
234 |
+
}
|
235 |
+
|
236 |
+
public function delete_item( &$item ) {
|
237 |
+
$index = array_search( (array) $item, $this->items, true );
|
238 |
+
|
239 |
+
if ( false === $index )
|
240 |
+
return;
|
241 |
+
|
242 |
+
unset( $this->items[ $index ] );
|
243 |
+
$this->amount -= $item->amount;
|
244 |
+
}
|
245 |
+
|
246 |
+
public function has_item_type( $item_type ) {
|
247 |
+
foreach ( $this->items as &$item ) {
|
248 |
+
if ( $item['item_type'] == $item_type )
|
249 |
+
return true;
|
250 |
+
}
|
251 |
+
|
252 |
+
return false;
|
253 |
+
}
|
254 |
+
|
255 |
+
public function get_items( $args = array() ) {
|
256 |
+
$items = array();
|
257 |
+
|
258 |
+
if ( isset( $args['item_type'] ) )
|
259 |
+
$args['item_type'] = is_array( $args['item_type'] ) ? $args['item_type'] : array( $args['item_type'] );
|
260 |
+
else
|
261 |
+
$args['item_type'] = null;
|
262 |
+
|
263 |
+
foreach ( $this->items as &$item ) {
|
264 |
+
if ( isset( $args['item_type'] ) && ! in_array( $item['item_type'], $args['item_type'], true ) )
|
265 |
+
continue;
|
266 |
+
|
267 |
+
if ( isset( $args['rel_id_1'] ) && $args['rel_id_1'] != $item['rel_id_1'] )
|
268 |
+
continue;
|
269 |
+
|
270 |
+
$items[] = $item;
|
271 |
+
}
|
272 |
+
|
273 |
+
return array_map( create_function( '$x', 'return (object) $x;' ), $items );
|
274 |
+
}
|
275 |
+
|
276 |
+
public function get_item( $args = array() ) {
|
277 |
+
$items = $this->get_items( $args );
|
278 |
+
|
279 |
+
if ( $items )
|
280 |
+
return array_pop( $items );
|
281 |
+
|
282 |
+
return null;
|
283 |
+
}
|
284 |
+
|
285 |
+
public function get_listing_id() {
|
286 |
+
return $this->listing_id;
|
287 |
+
}
|
288 |
+
|
289 |
+
public function get_total() {
|
290 |
+
return $this->amount;
|
291 |
+
}
|
292 |
+
|
293 |
+
public function get_status() {
|
294 |
+
return $this->status;
|
295 |
+
}
|
296 |
+
|
297 |
+
public function set_status( $newstatus, $processed_by = 'system', $processed_on = null ) {
|
298 |
+
$prev_status = $this->status;
|
299 |
+
$this->status = $newstatus;
|
300 |
+
$this->processed_by = $processed_by;
|
301 |
+
$this->processed_on = ! $processed_on ? current_time( 'mysql' ) : $processed_on;
|
302 |
+
|
303 |
+
if ( $prev_status != $newstatus )
|
304 |
+
do_action_ref_array( 'WPBDP_Payment::status_change', array( &$this, $prev_status, $newstatus ) );
|
305 |
+
}
|
306 |
+
|
307 |
+
public function get_gateway() {
|
308 |
+
return $this->gateway;
|
309 |
+
}
|
310 |
+
|
311 |
+
public function set_listing( $listing ) {
|
312 |
+
if ( is_object( $listing ) )
|
313 |
+
$this->listing_id = $listing->ID;
|
314 |
+
else
|
315 |
+
$this->listing_id = $listing;
|
316 |
+
}
|
317 |
+
|
318 |
+
public function set_payment_method( $method_id ) {
|
319 |
+
$this->gateway = $method_id;
|
320 |
+
|
321 |
+
do_action_ref_array( 'WPBDP_Payment::set_payment_method', array( &$this, $method_id ) );
|
322 |
+
}
|
323 |
+
|
324 |
+
public function get_currency_code() {
|
325 |
+
return $this->currency_code;
|
326 |
+
}
|
327 |
+
|
328 |
+
public function get_short_description() {
|
329 |
+
return $this->get_description();
|
330 |
+
}
|
331 |
+
|
332 |
+
// TODO
|
333 |
+
public function get_description() {
|
334 |
+
if ( count( $this->items ) == 1 )
|
335 |
+
return $this->items[0]['description'];
|
336 |
+
|
337 |
+
return sprintf( 'Listing Payment (ID: %s)', $this->id );
|
338 |
+
}
|
339 |
+
|
340 |
+
public function set_data( $key, $value ) {
|
341 |
+
if ( !is_array( $this->extra_data ) )
|
342 |
+
$this->extra_data = array();
|
343 |
+
|
344 |
+
$this->extra_data[ $key ] = $value;
|
345 |
+
}
|
346 |
+
|
347 |
+
public function get_data( $key ) {
|
348 |
+
if ( ! is_array( $this->extra_data ) || ! isset( $this->extra_data[ $key ] ) )
|
349 |
+
return null;
|
350 |
+
|
351 |
+
return $this->extra_data[ $key ];
|
352 |
+
}
|
353 |
+
|
354 |
+
public function set_submit_state_id( $id ) {
|
355 |
+
$this->set_data( 'submit_state_id', $id );
|
356 |
+
}
|
357 |
+
|
358 |
+
public function get_submit_state_id() {
|
359 |
+
return $this->get_data( 'submit_state_id' );
|
360 |
+
}
|
361 |
+
|
362 |
+
public function set_payer_info( $key, $value ) {
|
363 |
+
$this->payerinfo[ $key ] = $value;
|
364 |
+
}
|
365 |
+
|
366 |
+
public function get_payer_info( $key ) {
|
367 |
+
if ( isset( $this->payerinfo[ $key ] ) )
|
368 |
+
return $this->payerinfo[ $key ];
|
369 |
+
|
370 |
+
return '';
|
371 |
+
}
|
372 |
+
|
373 |
+
public function get_checkout_url( $force_http = false ) {
|
374 |
+
$payment_id = $this->id;
|
375 |
+
$payment_q = base64_encode('payment_id=' . $payment_id . '&verify=0' ); // TODO: add a 'verify' parameter to avoid false links being generated.
|
376 |
+
|
377 |
+
$base_url = wpbdp_get_page_link( 'main' );
|
378 |
+
|
379 |
+
if ( ! $force_http && ! is_ssl() && wpbdp_get_option( 'payments-use-https' ) ) {
|
380 |
+
$base_url = set_url_scheme( $base_url, 'https' );
|
381 |
+
}
|
382 |
+
|
383 |
+
return add_query_arg( array( 'action' => 'checkout', 'payment' => urlencode( $payment_q ) ), $base_url );
|
384 |
+
}
|
385 |
+
|
386 |
+
public function get_redirect_url() {
|
387 |
+
if ( $this->get_submit_state_id() ) {
|
388 |
+
if ( $this->is_completed() )
|
389 |
+
return add_query_arg( array( '_state' => $this->get_submit_state_id() ), wpbdp_get_page_link( 'submit' ) );
|
390 |
+
}
|
391 |
+
|
392 |
+
return $this->get_checkout_url( true );
|
393 |
+
}
|
394 |
+
|
395 |
+
public function get_created_on() {
|
396 |
+
return $this->created_on;
|
397 |
+
}
|
398 |
+
|
399 |
+
public function add_error( $error_msg ) {
|
400 |
+
// TODO: add datetime support.
|
401 |
+
$errors = $this->get_data( 'errors' );
|
402 |
+
$errors = ! $errors ? array() : $errors;
|
403 |
+
|
404 |
+
$errors[] = $error_msg;
|
405 |
+
|
406 |
+
$this->set_data( 'errors', $errors );
|
407 |
+
}
|
408 |
+
|
409 |
+
public function clear_errors() {
|
410 |
+
$this->set_data( 'errors', array() );
|
411 |
+
}
|
412 |
+
|
413 |
+
public function get_notes() {
|
414 |
+
return $this->notes;
|
415 |
+
}
|
416 |
+
|
417 |
+
/* @override */
|
418 |
+
public static function find( $args = array(), $lightweight = false ) {
|
419 |
+
global $wpdb;
|
420 |
+
return parent::_find( $args, $lightweight, $wpdb->prefix . 'wpbdp_payments', __CLASS__ );
|
421 |
+
}
|
422 |
+
|
423 |
+
/* @override */
|
424 |
+
public static function get( $id ) {
|
425 |
+
global $wpdb;
|
426 |
+
return parent::_get( $id, $wpdb->prefix . 'wpbdp_payments', __CLASS__ );
|
427 |
+
}
|
428 |
+
|
429 |
+
}
|
430 |
+
?>
|
core/class-settings.php
ADDED
@@ -0,0 +1,1258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPBDP_Settings {
|
3 |
+
|
4 |
+
const PREFIX = 'wpbdp-';
|
5 |
+
|
6 |
+
const _EMAIL_RENEWAL_MESSAGE = "Your listing \"[listing]\" in category [category] expired on [expiration]. To renew your listing click the link below.\n[link]";
|
7 |
+
const _EMAIL_AUTORENEWAL_MESSAGE = "Hey [author],\n\nThanks for your payment. We just renewed your listing [listing] on [date] for another period.\n\nIf you have any questions, contact us at [site].";
|
8 |
+
const _EMAIL_AUTORENEWAL_PENDING_MESSAGE = "Hey [author],\n\nThis is just to remind you that your listing [listing] is going to be renewed on [date] for another period.\nIf you want to review or cancel your subscriptions please visit [link].\n\nIf you have any questions, contact us at [site].";
|
9 |
+
const _EMAIL_PENDING_RENEWAL_MESSAGE = 'Your listing "[listing]" is about to expire at [site]. You can renew it here: [link].';
|
10 |
+
|
11 |
+
private $deps = array();
|
12 |
+
|
13 |
+
|
14 |
+
public function __construct() {
|
15 |
+
$this->groups = array();
|
16 |
+
$this->settings = array();
|
17 |
+
|
18 |
+
add_action( 'wp_ajax_wpbdp-admin-settings-email-preview', array( &$this, '_ajax_email_preview' ) );
|
19 |
+
add_filter( 'wpbdp_settings_render', array( &$this, 'after_render' ), 0, 3 );
|
20 |
+
}
|
21 |
+
|
22 |
+
public function register_settings() {
|
23 |
+
/* General settings */
|
24 |
+
$g = $this->add_group('general', _x('General', 'admin settings', 'WPBDM'));
|
25 |
+
|
26 |
+
$s = $this->add_section( $g, 'tracking', _x( 'Data Collection', 'admin settings', 'WPBDM' ) );
|
27 |
+
$this->add_setting( $s,
|
28 |
+
'tracking-on',
|
29 |
+
_x( 'Allow BD to anonymously collect information about your installed plugins, themes and WP version?', 'admin settings', 'WPBDM' ),
|
30 |
+
'boolean',
|
31 |
+
false,
|
32 |
+
str_replace( '<a>',
|
33 |
+
'<a href="http://businessdirectoryplugin.com/what-we-track/" target="_blank">',
|
34 |
+
_x( '<a>Learn more</a> about what BD does and does NOT track.', 'admin settings', 'WPBDM' ) )
|
35 |
+
);
|
36 |
+
|
37 |
+
$s = $this->add_section($g, 'permalink', _x('Permalink Settings', 'admin settings', 'WPBDM'));
|
38 |
+
$this->add_setting($s, 'permalinks-directory-slug', _x('Directory Listings Slug', 'admin settings', 'WPBDM'), 'text', WPBDP_POST_TYPE, null, null, array($this, '_validate_listings_permalink'));
|
39 |
+
$this->add_setting($s, 'permalinks-category-slug', _x('Categories Slug', 'admin settings', 'WPBDM'), 'text', WPBDP_CATEGORY_TAX, _x('The slug can\'t be in use by another term. Avoid "category", for instance.', 'admin settings', 'WPBDM'), null, array($this, '_validate_term_permalink'));
|
40 |
+
$this->add_setting($s, 'permalinks-tags-slug', _x('Tags Slug', 'admin settings', 'WPBDM'), 'text', WPBDP_TAGS_TAX, _x('The slug can\'t be in use by another term. Avoid "tag", for instance.', 'admin settings', 'WPBDM'), null, array($this, '_validate_term_permalink'));
|
41 |
+
$this->add_setting( $s,
|
42 |
+
'permalinks-no-id',
|
43 |
+
_x( 'Remove listing ID from directory URLs?', 'admin settings', 'WPBDM' ),
|
44 |
+
'boolean',
|
45 |
+
false );
|
46 |
+
|
47 |
+
$s = $this->add_section( $g,
|
48 |
+
'recaptcha',
|
49 |
+
_x( 'reCAPTCHA Settings', 'admin settings', 'WPBDM' ),
|
50 |
+
str_replace( '<a>',
|
51 |
+
'<a href="http://www.recaptcha.com" target="_blank">',
|
52 |
+
_x( 'Need API keys for reCAPTCHA? Get them <a>here</a>.', 'admin settings', 'WPBDM' ) )
|
53 |
+
);
|
54 |
+
$this->add_setting($s, 'recaptcha-on', _x('Use reCAPTCHA for contact forms', 'admin settings', 'WPBDM'), 'boolean', false);
|
55 |
+
$this->add_setting($s, 'recaptcha-for-submits', _x('Use reCAPTCHA for listing submits', 'admin settings', 'WPBDM'), 'boolean', false);
|
56 |
+
$this->add_setting( $s,
|
57 |
+
'recaptcha-for-comments',
|
58 |
+
_x( 'Use reCAPTCHA for listing comments?', 'admin settings', 'WPBDM' ),
|
59 |
+
'boolean',
|
60 |
+
false );
|
61 |
+
$this->add_setting($s, 'recaptcha-public-key', _x('reCAPTCHA Public Key', 'admin settings', 'WPBDM'));
|
62 |
+
$this->add_setting($s, 'recaptcha-private-key', _x('reCAPTCHA Private Key', 'admin settings', 'WPBDM'));
|
63 |
+
|
64 |
+
$s = $this->add_section( $g,
|
65 |
+
'terms-and-conditions',
|
66 |
+
_x( 'Terms and Conditions', 'admin settings', 'WPBDM' ) );
|
67 |
+
$this->add_setting( $s,
|
68 |
+
'display-terms-and-conditions',
|
69 |
+
_x( 'Display and require user agreement to Terms and Conditions', 'admin settings', 'WPBDM' ),
|
70 |
+
'boolean',
|
71 |
+
false
|
72 |
+
);
|
73 |
+
$this->add_setting( $s,
|
74 |
+
'terms-and-conditions',
|
75 |
+
_x( 'Terms and Conditions', 'admin settings', 'WPBDM' ),
|
76 |
+
'text',
|
77 |
+
"Terms and Conditions text goes here...\n\n",
|
78 |
+
_x( 'Enter text or a URL starting with http. If you use a URL, the Terms and Conditions text will be replaced by a link to the appropiate page.', 'admin settings', 'WPBDM' ),
|
79 |
+
array( 'use_textarea' => true )
|
80 |
+
);
|
81 |
+
|
82 |
+
$s = $this->add_section($g, 'displayoptions', _x('Directory Display Options', 'admin settings', 'WPBDM'));
|
83 |
+
$this->add_setting($s, 'show-submit-listing', _x('Show the "Submit listing" button.', 'admin settings', 'WPBDM'), 'boolean', true);
|
84 |
+
$this->add_setting($s, 'show-search-listings', _x('Show "Search listings".', 'admin settings', 'WPBDM'), 'boolean', true);
|
85 |
+
$this->add_setting($s, 'show-view-listings', _x('Show the "View Listings" button.', 'admin settings', 'WPBDM'), 'boolean', true);
|
86 |
+
$this->add_setting($s, 'show-directory-button', _x('Show the "Directory" button.', 'admin settings', 'WPBDM'), 'boolean', true);
|
87 |
+
|
88 |
+
// {{ Directory search.
|
89 |
+
$s = $this->add_section( $g,
|
90 |
+
'search',
|
91 |
+
_x( 'Directory Search', 'admin settings', 'WPBDM' ) );
|
92 |
+
$this->add_setting( $s,
|
93 |
+
'show-search-form-in-results',
|
94 |
+
_x( 'Display search form when displaying search results?', 'admin settings', 'WPBDM' ),
|
95 |
+
'boolean',
|
96 |
+
true );
|
97 |
+
|
98 |
+
// Quick search fields.
|
99 |
+
$desc = '';
|
100 |
+
$desc .= '<span class="text-fields-warning wpbdp-note" style="display: none;">';
|
101 |
+
$desc .= _x( 'You have selected a textarea field to be included in quick searches. Searches involving those fields are very expensive and could result in timeouts and/or general slowness.', 'admin settings', 'WPBDM' );
|
102 |
+
$desc .= '</span>';
|
103 |
+
$desc .= _x( 'Choosing too many fields for inclusion into Quick Search can result in very slow search performance.', 'admin settings', 'WPBDM' );
|
104 |
+
$this->add_setting( $s,
|
105 |
+
'quick-search-fields',
|
106 |
+
_x( 'Quick search fields', 'admin settings', 'WPBDM' ),
|
107 |
+
'choice',
|
108 |
+
array(),
|
109 |
+
$desc,
|
110 |
+
array( 'choices' => array( &$this, 'quicksearch_fields_cb' ), 'use_checkboxes' => false, 'multiple' => true )
|
111 |
+
);
|
112 |
+
// }}
|
113 |
+
|
114 |
+
// Misc. settings.
|
115 |
+
|
116 |
+
$s = $this->add_section($g, 'misc', _x('Miscellaneous Settings', 'admin settings', 'WPBDM'));
|
117 |
+
$this->add_setting($s, 'hide-tips', _x('Hide tips for use and other information?', 'admin settings', 'WPBDM'), 'boolean', false);
|
118 |
+
|
119 |
+
/* Listings settings */
|
120 |
+
$g = $this->add_group('listings', _x('Listings', 'admin settings', 'WPBDM'));
|
121 |
+
$s = $this->add_section($g, 'general', _x('General Settings', 'admin settings', 'WPBDM'));
|
122 |
+
|
123 |
+
$this->add_setting($s, 'listings-per-page', _x('Listings per page', 'admin settings', 'WPBDM'), 'text', '10',
|
124 |
+
_x('Number of listings to show per page. Use a value of "0" to show all listings.', 'admin settings', 'WPBDM'));
|
125 |
+
|
126 |
+
$this->add_setting($s, 'listing-duration', _x('Listing duration for no-fee sites (in days)', 'admin settings', 'WPBDM'), 'text', '365',
|
127 |
+
_x('Use a value of "0" to keep a listing alive indefinitely or enter a number less than 10 years (3650 days).', 'admin settings', 'WPBDM'),
|
128 |
+
null,
|
129 |
+
array($this, '_validate_listing_duration'));
|
130 |
+
|
131 |
+
$this->add_setting( $s,
|
132 |
+
'show-contact-form',
|
133 |
+
_x( 'Include listing contact form on listing pages?', 'admin settings', 'WPBDM' ),
|
134 |
+
'boolean',
|
135 |
+
true,
|
136 |
+
_x( 'Allows visitors to contact listing authors privately. Authors will receive the messages via email.', 'admin settings', 'WPBDM' ) );
|
137 |
+
$this->add_setting( $s,
|
138 |
+
'contact-form-require-login',
|
139 |
+
_x( 'Require login for using the contact form?', 'admin settings', 'WPBDM' ),
|
140 |
+
'boolean',
|
141 |
+
false );
|
142 |
+
$this->register_dep( 'contact-form-require-login', 'requires-true', 'show-contact-form' );
|
143 |
+
$this->add_setting( $s,
|
144 |
+
'contact-form-daily-limit',
|
145 |
+
_x( 'Maximum number of contact form submits per day', 'admin settings', 'WPBDM' ),
|
146 |
+
'text',
|
147 |
+
'0',
|
148 |
+
_x( 'Use this to prevent spamming of listing owners. 0 means unlimited submits per day.',
|
149 |
+
'admin settings',
|
150 |
+
'WPBDM') );
|
151 |
+
$this->register_dep( 'contact-form-daily-limit', 'requires-true', 'show-contact-form' );
|
152 |
+
$this->add_setting( $s,
|
153 |
+
'show-comment-form',
|
154 |
+
_x( 'Include comment form on listing pages?', 'admin settings', 'WPBDM' ),
|
155 |
+
'boolean',
|
156 |
+
false,
|
157 |
+
_x( 'Allow visitors to discuss listings using the standard WordPress comment form. Comments are public.', 'admin settings', 'WPBDM' ) );
|
158 |
+
$this->add_setting($s, 'show-listings-under-categories', _x('Show listings under categories on main page?', 'admin settings', 'WPBDM'), 'boolean', false);
|
159 |
+
$this->add_setting($s, 'status-on-uninstall', _x('Status of listings upon uninstalling plugin', 'admin settings', 'WPBDM'), 'choice', 'trash', '',
|
160 |
+
array('choices' => array('draft', 'trash')));
|
161 |
+
$this->add_setting($s, 'deleted-status', _x('Status of deleted listings', 'admin settings', 'WPBDM'), 'choice', 'trash', '',
|
162 |
+
array('choices' => array('draft', 'trash')));
|
163 |
+
|
164 |
+
$s = $this->add_section($g, 'listings/renewals', _x('Listing Renewal', 'admin settings', 'WPBDM'));
|
165 |
+
$this->add_setting($s, 'listing-renewal', _x('Turn on listing renewal option?', 'admin settings', 'WPBDM'), 'boolean', true);
|
166 |
+
$this->add_setting( $s,
|
167 |
+
'listing-renewal-auto',
|
168 |
+
_x( 'Allow recurring renewal payments?', 'admin settings', 'WPBDM' ),
|
169 |
+
'boolean',
|
170 |
+
false,
|
171 |
+
_x( 'Allow users to opt in for automatic renewal of their listings. The fee is charged at the time the listing expires without user intervention.', 'admin settings', 'WPBDM' )
|
172 |
+
);
|
173 |
+
$this->add_setting( $s,
|
174 |
+
'listing-renewal-auto-dontask',
|
175 |
+
_x( 'Use recurring payments as the default payment method?', 'admin settings', 'WPBDM' ),
|
176 |
+
'boolean',
|
177 |
+
false,
|
178 |
+
_x( 'Enable automatic renewal without having users opt in during the submit process.', 'admin settings', 'WPBDM' ) );
|
179 |
+
$this->register_dep( 'listing-renewal-auto-dontask', 'requires-true', 'listing-renewal-auto' );
|
180 |
+
|
181 |
+
$this->add_setting( $s,
|
182 |
+
'renewal-email-threshold',
|
183 |
+
_x( 'Listing renewal e-mail threshold (in days)', 'admin settings', 'WPBDM' ),
|
184 |
+
'text',
|
185 |
+
'5',
|
186 |
+
_x( 'Configure how many days before listing expiration is the renewal e-mail sent.', 'admin settings', 'WPBDM' )
|
187 |
+
);
|
188 |
+
$this->add_setting( $s,
|
189 |
+
'send-autorenewal-expiration-notice',
|
190 |
+
_x( 'Send expiration notices including a cancel links to auto-renewed listings?', 'admin settings', 'WPBDM' ),
|
191 |
+
'boolean',
|
192 |
+
false );
|
193 |
+
|
194 |
+
// Renewal Reminders
|
195 |
+
$this->add_setting( $s,
|
196 |
+
'renewal-reminder',
|
197 |
+
_x( 'Remind listing owners of expired listings (past due)?', 'admin settings', 'WPBDM' ),
|
198 |
+
'boolean',
|
199 |
+
false );
|
200 |
+
$this->add_setting( $s,
|
201 |
+
'renewal-reminder-threshold',
|
202 |
+
_x( 'Listing renewal reminder e-mail threshold (in days)', 'admin settings', 'WPBDM' ),
|
203 |
+
'text',
|
204 |
+
'10',
|
205 |
+
_x( 'Configure how many days after the expiration of a listing an e-mail reminder should be sent to the owner.', 'admin settings', 'WPBDM' )
|
206 |
+
);
|
207 |
+
|
208 |
+
$s = $this->add_section($g, 'post/category', _x('Post/Category Settings', 'admin settings', 'WPBDM'));
|
209 |
+
$this->add_setting($s, 'new-post-status', _x('Default new post status', 'admin settings', 'WPBDM'), 'choice', 'pending', '',
|
210 |
+
array('choices' => array('publish', 'pending'))
|
211 |
+
);
|
212 |
+
$this->add_setting($s, 'edit-post-status', _x('Edit post status', 'admin settings', 'WPBDM'), 'choice', 'publish', '',
|
213 |
+
array('choices' => array('publish', 'pending')));
|
214 |
+
$this->add_setting( $s, 'categories-order-by', _x('Order categories list by', 'admin settings', 'WPBDM'), 'choice', 'name', '',
|
215 |
+
array('choices' => array(
|
216 |
+
array( 'name', _x( 'Name', 'admin settings', 'WPBDM' ) ),
|
217 |
+
array( 'slug', _x( 'Slug', 'admin settings', 'WPBDM' ) ),
|
218 |
+
array( 'count', _x( 'Listing Count', 'admin settings', 'WPBDM' ) )
|
219 |
+
)) );
|
220 |
+
$this->add_setting( $s, 'categories-sort', _x('Sort order for categories', 'admin settings', 'WPBDM'), 'choice', 'ASC', '',
|
221 |
+
array('choices' => array(array('ASC', _x('Ascending', 'admin settings', 'WPBDM')), array('DESC', _x('Descending', 'admin settings', 'WPBDM')))));
|
222 |
+
$this->add_setting($s, 'show-category-post-count', _x('Show category post count?', 'admin settings', 'WPBDM'), 'boolean', true);
|
223 |
+
$this->add_setting($s, 'hide-empty-categories', _x('Hide empty categories?', 'admin settings', 'WPBDM'), 'boolean', false);
|
224 |
+
$this->add_setting($s, 'show-only-parent-categories', _x('Show only parent categories in category list?', 'admin settings', 'WPBDM'), 'boolean', false);
|
225 |
+
|
226 |
+
$s = $this->add_section( $g, 'post/sorting', _x( 'Listings Sorting', 'admin settings', 'WPBDM' ) );
|
227 |
+
$this->add_setting($s, 'listings-order-by', _x('Order directory listings by', 'admin settings', 'WPBDM'), 'choice', 'title', '',
|
228 |
+
array('choices' => array(
|
229 |
+
array( 'title', _x( 'Title', 'admin settings', 'WPBDM' ) ),
|
230 |
+
array( 'author', _x( 'Author', 'admin settings', 'WPBDM' ) ),
|
231 |
+
array( 'date', _x( 'Date posted', 'admin settings', 'WPBDM' ) ),
|
232 |
+
array( 'modified', _x( 'Date last modified', 'admin settings', 'WPBDM' ) ),
|
233 |
+
array( 'rand', _x( 'Random', 'admin settings', 'WPBDM' ) ),
|
234 |
+
array( 'paid', _x( 'Paid first then free', 'admin settings', 'WPBDM' ) )
|
235 |
+
)));
|
236 |
+
$this->add_setting( $s, 'listings-sort', _x('Sort directory listings by', 'admin settings', 'WPBDM'), 'choice', 'ASC',
|
237 |
+
_x('Ascending for ascending order A-Z, Descending for descending order Z-A', 'admin settings', 'WPBDM'),
|
238 |
+
array('choices' => array(array('ASC', _x('Ascending', 'admin settings', 'WPBDM')), array('DESC', _x('Descending', 'admin settings', 'WPBDM')))));
|
239 |
+
|
240 |
+
$this->add_setting( $s,
|
241 |
+
'listings-sortbar-enabled',
|
242 |
+
_x( 'Enable sort bar?', 'admin settings', 'WPBDM' ),
|
243 |
+
'boolean',
|
244 |
+
false );
|
245 |
+
$this->add_setting( $s,
|
246 |
+
'listings-sortbar-fields',
|
247 |
+
_x( 'Sortbar Fields', 'admin settings', 'WPBDM' ),
|
248 |
+
'choice',
|
249 |
+
array(),
|
250 |
+
'',
|
251 |
+
array( 'choices' => array( &$this, 'sortbar_fields_cb' ),
|
252 |
+
'use_checkboxes' => true,
|
253 |
+
'multiple' =>true ) );
|
254 |
+
$this->register_dep( 'listings-sortbar-fields', 'requires-true', 'listings-sortbar-enabled' );
|
255 |
+
|
256 |
+
$s = $this->add_section($g, 'featured', _x('Featured (Sticky) listing settings', 'admin settings', 'WPBDM'));
|
257 |
+
$this->add_setting($s, 'featured-on', _x('Offer sticky listings?', 'admin settings', 'WPBDM'), 'boolean', true);
|
258 |
+
$this->add_setting($s, 'featured-offer-in-submit', _x('Offer upgrades during submit process?', 'admin settings', 'WPBDM'), 'boolean', false);
|
259 |
+
$this->add_setting($s, 'featured-price', _x('Sticky listing price', 'admin settings', 'WPBDM'), 'text', '39.99');
|
260 |
+
$this->add_setting($s, 'featured-description', _x('Sticky listing page description text', 'admin settings', 'WPBDM'), 'text',
|
261 |
+
_x('You can upgrade your listing to featured status. Featured listings will always appear on top of regular listings.', 'admin settings', 'WPBDM'));
|
262 |
+
|
263 |
+
/*
|
264 |
+
* E-Mail settings.
|
265 |
+
*/
|
266 |
+
$g = $this->add_group( 'email', _x( 'E-Mail', 'admin settings', 'WPBDM' ) );
|
267 |
+
$s = $this->add_section( $g, 'email-general', _x( 'General Settings', 'admin settings', 'WPBDM' ) );
|
268 |
+
$this->add_setting( $s,
|
269 |
+
'override-email-blocking',
|
270 |
+
_x( 'Display email address fields publicly?', 'admin settings', 'WPBDM' ),
|
271 |
+
'boolean',
|
272 |
+
false,
|
273 |
+
_x('Shows the email address of the listing owner to all web users. NOT RECOMMENDED as this increases spam to the address and allows spam bots to harvest it for future use.', 'admin settings', 'WPBDM') );
|
274 |
+
$this->add_setting( $s,
|
275 |
+
'listing-email-mode',
|
276 |
+
_x( 'How to determine the listing\'s email address?', 'admin settings', 'WPBDM' ),
|
277 |
+
'choice',
|
278 |
+
'field',
|
279 |
+
_x( 'This affects emails sent to listing owners via contact forms or when their listings expire.', 'admin settings', 'WPBDM' ),
|
280 |
+
array( 'choices' => array(
|
281 |
+
array( 'field', 'Try listing\'s email field first, then author\'s email.' ),
|
282 |
+
array( 'user', 'Try author\'s email first and then listing\'s email field.' )
|
283 |
+
|
284 |
+
) ) );
|
285 |
+
|
286 |
+
$s = $this->add_section( $g, 'email-notifications', _x( 'E-Mail Notifications', 'admin settings', 'WPBDM' ) );
|
287 |
+
$this->add_setting( $s,
|
288 |
+
'admin-notifications',
|
289 |
+
_x( 'Notify admin via e-mail when...', 'admin settings', 'WPBDM' ),
|
290 |
+
'choice',
|
291 |
+
array(),
|
292 |
+
'',
|
293 |
+
array( 'choices' => array( 'new-listing' => _x( 'A new listing is submitted.', 'admin settings', 'WPBDM' ),
|
294 |
+
'listing-edit' => _x( 'A listing is edited.', 'admin settings', 'WPBDM' ),
|
295 |
+
'renewal' => _x( 'A listing expires.', 'admin settings', 'WPBDM' ),
|
296 |
+
'listing-contact' => _x( 'A contact message is sent to a listing\'s owner.', 'admin settings', 'WPBDM' ) ),
|
297 |
+
'use_checkboxes' => true,
|
298 |
+
'multiple' => true )
|
299 |
+
);
|
300 |
+
$this->add_setting( $s,
|
301 |
+
'admin-notifications-cc',
|
302 |
+
_x( 'CC this e-mail address too', 'admin settings', 'WPBDM' ),
|
303 |
+
'text',
|
304 |
+
'' );
|
305 |
+
|
306 |
+
$this->add_setting( $s,
|
307 |
+
'user-notifications',
|
308 |
+
_x( 'Notify users via e-mail when...', 'admin settings', 'WPBDM' ),
|
309 |
+
'choice',
|
310 |
+
array( 'new-listing', 'listing-published'/*, 'payment-status-change'*/ ),
|
311 |
+
_x( 'You can modify the text template used for most of these e-mails below.', 'admin settings', 'WPBDM' ),
|
312 |
+
array( 'choices' => array( 'new-listing' => _x( 'Their listing is submitted.', 'admin settings', 'WPBDM' ),
|
313 |
+
'listing-published' => _x( 'Their listing is approved/published.', 'admin settings', 'WPBDM' )/*,
|
314 |
+
'payment-status-change' => _x( 'A payment status changes (sends a receipt).', 'admin settings', 'WPBDM' ),*/
|
315 |
+
),
|
316 |
+
'use_checkboxes' => true,
|
317 |
+
'multiple' => true )
|
318 |
+
);
|
319 |
+
|
320 |
+
// Listing contact.
|
321 |
+
$email_contact_template = '';
|
322 |
+
$email_contact_template .= sprintf( _x( 'You have received a reply from your listing at %s.', 'contact email', 'WPBDM' ), '[listing-url]' ) . "\n\n";
|
323 |
+
$email_contact_template .= sprintf( _x( 'Name: %s', 'contact email', 'WPBDM' ), '[name]' ) . "\n";
|
324 |
+
$email_contact_template .= sprintf( _x( 'E-Mail: %s', 'contact email', 'WPBDM' ), '[email]' ) . "\n";
|
325 |
+
$email_contact_template .= _x( 'Message:', 'contact email', 'WPBDM' ) . "\n";
|
326 |
+
$email_contact_template .= '[message]' . "\n\n";
|
327 |
+
$email_contact_template .= sprintf( _x( 'Time: %s', 'contact email', 'WPBDM' ), '[date]' );
|
328 |
+
|
329 |
+
$s = $this->add_section( $g, 'email/templates', _x( 'E-Mail Templates', 'admin settings', 'WPBDM' ) );
|
330 |
+
|
331 |
+
$this->add_setting( $s,
|
332 |
+
'email-confirmation-message', _x( 'Email confirmation message', 'admin settings', 'WPBDM' ),
|
333 |
+
'email_template',
|
334 |
+
array( 'subject' => '[[site-title]] Listing "[listing]" received',
|
335 |
+
'body' => 'Your submission \'[listing]\' has been received and it\'s pending review. This review process could take up to 48 hours.' ),
|
336 |
+
_x( 'Sent after a listing has been submitted.', 'admin settings', 'WPBDM' ),
|
337 |
+
array( 'placeholders' => array( 'listing' => array( _x( 'Listing\'s title', 'admin settings', 'WPBDM' ) ) ) )
|
338 |
+
);
|
339 |
+
$this->add_setting( $s,
|
340 |
+
'email-templates-listing-published', _x( 'Listing published message', 'admin settings', 'WPBDM' ),
|
341 |
+
'email_template',
|
342 |
+
array( 'subject' => '[[site-title]] Listing "[listing]" published',
|
343 |
+
'body' => _x( 'Your listing "[listing]" is now available at [listing-url] and can be viewed by the public.', 'admin settings', 'WPBDM' ) ),
|
344 |
+
_x( 'Sent when the listing has been published or approved by an admin.', 'admin settings', 'WPBDM' ),
|
345 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s title', 'admin settings', 'WPBDM' ),
|
346 |
+
'listing-url' => _x( 'Listing\'s URL', 'admin settings', 'WPBDM' ) ) )
|
347 |
+
);
|
348 |
+
$this->add_setting( $s,
|
349 |
+
'email-templates-contact',
|
350 |
+
_x( 'Listing Contact Message', 'admin settings', 'WPBDM' ),
|
351 |
+
'email_template',
|
352 |
+
array( 'subject' => '[[site-title]] Contact via "[listing]"',
|
353 |
+
'body' => $email_contact_template ),
|
354 |
+
_x( 'Sent to listing owners when someone uses the contact form on their listing pages.', 'admin settings', 'WPBDM' ),
|
355 |
+
array( 'placeholders' => array( 'listing-url' => 'Listing\'s URL',
|
356 |
+
'listing' => 'Listing\'s title',
|
357 |
+
'name' => 'Sender\'s name',
|
358 |
+
'email' => 'Sender\'s e-mail address',
|
359 |
+
'message' => 'Contact message',
|
360 |
+
'date' => 'Date and time the message was sent' ) ) );
|
361 |
+
|
362 |
+
$s = $this->add_section( $g,
|
363 |
+
'email-renewal-reminders',
|
364 |
+
_x( 'Renewal Reminders', 'admin settings', 'WPBDM' ),
|
365 |
+
str_replace( '<a>',
|
366 |
+
'<a href="' . admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=listings#listings/renewals' ) . '">',
|
367 |
+
_x( 'This section refers only to the text of the renewal/expiration notices. You can also <a>configure when the e-mails are sent</a>.', 'admin settings', 'WPBDM' ) ) );
|
368 |
+
|
369 |
+
$this->add_setting( $s,
|
370 |
+
'renewal-pending-message',
|
371 |
+
_x( 'Pending expiration e-mail message', 'admin settings', 'WPBDM' ),
|
372 |
+
'email_template',
|
373 |
+
array( 'subject' => '[[site-title]] [listing] - Expiration notice',
|
374 |
+
'body' => self::_EMAIL_PENDING_RENEWAL_MESSAGE ),
|
375 |
+
_x( 'Sent some time before the listing expires. Applies to non-recurring renewals only.', 'settings', 'WPBDM' ),
|
376 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s name (with link)', 'settings', 'WPBDM' ),
|
377 |
+
'author' => _x( 'Author\'s name', 'settings', 'WPBDM' ),
|
378 |
+
'expiration' => _x( 'Expiration date', 'settings', 'WPBDM' ),
|
379 |
+
'category' => _x( 'Category that is going to expire', 'settings', 'WPBDM' ),
|
380 |
+
'link' => _x( 'Link to renewal page', 'settings', 'WPBDM' ),
|
381 |
+
'site' => _x( 'Link to your site', 'settings', 'WPBDM' ) ) )
|
382 |
+
);
|
383 |
+
$this->add_setting( $s,
|
384 |
+
'listing-renewal-message', _x('Listing Renewal e-mail message', 'admin settings', 'WPBDM'),
|
385 |
+
'email_template',
|
386 |
+
array( 'subject' => '[[site-title]] [listing] - Expiration notice',
|
387 |
+
'body' => self::_EMAIL_RENEWAL_MESSAGE ),
|
388 |
+
_x( 'Sent at the time of listing expiration. Applies to non-recurring renewals only.', 'settings', 'WPBDM' ),
|
389 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s name (with link)', 'settings', 'WPBDM' ),
|
390 |
+
'author' => _x( 'Author\'s name', 'settings', 'WPBDM' ),
|
391 |
+
'expiration' => _x( 'Expiration date', 'settings', 'WPBDM' ),
|
392 |
+
'category' => _x( 'Category that expired', 'settings', 'WPBDM' ),
|
393 |
+
'link' => _x( 'Link to renewal page', 'settings', 'WPBDM' ),
|
394 |
+
'site' => _x( 'Link to your site', 'settings', 'WPBDM' ) ) )
|
395 |
+
);
|
396 |
+
$this->add_setting( $s,
|
397 |
+
'listing-autorenewal-notice', _x( 'Listing auto-renewal reminder (recurring payments)', 'admin settings', 'WPBDM'),
|
398 |
+
'email_template',
|
399 |
+
array( 'subject' => '[[site-title]] [listing] - Renewal reminder',
|
400 |
+
'body' => self::_EMAIL_AUTORENEWAL_PENDING_MESSAGE ),
|
401 |
+
_x( 'Sent some time before the listing is auto-renewed. Applies to recurring renewals only.', 'settings', 'WPBDM' ),
|
402 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s name (with link)', 'settings', 'WPBDM' ),
|
403 |
+
'author' => _x( 'Author\'s name', 'settings', 'WPBDM' ),
|
404 |
+
'date' => _x( 'Renewal date', 'settings', 'WPBDM' ),
|
405 |
+
'category' => _x( 'Category that is going to be renewed', 'settings', 'WPBDM' ),
|
406 |
+
'site' => _x( 'Link to your site', 'settings', 'WPBDM' ),
|
407 |
+
'link' => _x( 'Link to manage subscriptions', 'settings', 'WPBDM' ) ) )
|
408 |
+
);
|
409 |
+
$this->add_setting( $s,
|
410 |
+
'listing-autorenewal-message', _x('Listing Renewal e-mail message (recurring payments)', 'admin settings', 'WPBDM'),
|
411 |
+
'email_template',
|
412 |
+
array( 'subject' => '[[site-title]] [listing] renewed',
|
413 |
+
'body' => self::_EMAIL_AUTORENEWAL_MESSAGE ),
|
414 |
+
_x( 'Sent after the listing is auto-renewed. Applies to recurring renewals only.', 'settings', 'WPBDM' ),
|
415 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s name (with link)', 'settings', 'WPBDM' ),
|
416 |
+
'author' => _x( 'Author\'s name', 'settings', 'WPBDM' ),
|
417 |
+
'category' => _x( 'Renewed category', 'settings', 'WPBDM' ),
|
418 |
+
'date' => _x( 'Renewal date', 'settings', 'WPBDM' ),
|
419 |
+
'site' => _x( 'Link to your site', 'settings', 'WPBDM' ) ) )
|
420 |
+
);
|
421 |
+
$this->add_setting( $s,
|
422 |
+
'renewal-reminder-message',
|
423 |
+
_x( 'Renewal reminder e-mail message', 'admin settings', 'WPBDM' ),
|
424 |
+
'email_template',
|
425 |
+
array( 'subject' => '[[site-title]] [listing] - Expiration reminder',
|
426 |
+
'body' => "Dear Customer\nWe've noticed that you haven't renewed your listing \"[listing]\" for category [category] at [site] and just wanted to remind you that it expired on [expiration]. Please remember you can still renew it here: [link]." ),
|
427 |
+
_x( 'Sent some time after listing expiration and when no renewal has occurred. Applies to both recurring and non-recurring renewals.', 'settings', 'WPBDM' ),
|
428 |
+
array( 'placeholders' => array( 'listing' => _x( 'Listing\'s name (with link)', 'settings', 'WPBDM' ),
|
429 |
+
'author' => _x( 'Author\'s name', 'settings', 'WPBDM' ),
|
430 |
+
'expiration' => _x( 'Expiration date', 'settings', 'WPBDM' ),
|
431 |
+
'category' => _x( 'Category that expired', 'settings', 'WPBDM' ),
|
432 |
+
'link' => _x( 'Link to renewal page', 'settings', 'WPBDM' ),
|
433 |
+
'site' => _x( 'Link to your site', 'settings', 'WPBDM' ) ) )
|
434 |
+
);
|
435 |
+
|
436 |
+
/* Payment settings */
|
437 |
+
$g = $this->add_group('payment', _x('Payment', 'admin settings', 'WPBDM'));
|
438 |
+
$s = $this->add_section($g, 'general', _x('Payment Settings', 'admin settings', 'WPBDM'));
|
439 |
+
|
440 |
+
$this->add_setting( $s, 'fee-order', 'Fee Order', 'core', array( 'method' => 'label', 'order' => 'asc' ) );
|
441 |
+
$this->add_setting($s, 'payments-on', _x('Turn On payments?', 'admin settings', 'WPBDM'), 'boolean', false);
|
442 |
+
|
443 |
+
$this->add_setting($s, 'payments-test-mode', _x('Put payment gateways in test mode?', 'admin settings', 'WPBDM'), 'boolean', true);
|
444 |
+
$this->register_dep( 'payments-test-mode', 'requires-true', 'payments-on' );
|
445 |
+
|
446 |
+
$this->add_setting( $s,
|
447 |
+
'payments-use-https',
|
448 |
+
_x( 'Perform checkouts on the secure (HTTPS) version of your site?', 'admin settings', 'WPBDM' ),
|
449 |
+
'boolean',
|
450 |
+
false,
|
451 |
+
_x( 'Recommended for added security. For this to work you need to enable HTTPS on your server and <a>obtain an SSL certificate</a>.', 'admin settings', 'WPBDM' ) );
|
452 |
+
$this->register_dep( 'payments-use-https', 'requires-true', 'payments-on' );
|
453 |
+
|
454 |
+
// PayPal currency codes from https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_currency_codes
|
455 |
+
$this->add_setting($s, 'currency', _x('Currency Code', 'admin settings', 'WPBDM'), 'choice', 'USD', '',
|
456 |
+
array('choices' => array(
|
457 |
+
array('AUD', _x('Australian Dollar (AUD)', 'admin settings', 'WPBDM')),
|
458 |
+
array('BRL', _x('Brazilian Real (BRL)', 'admin settings', 'WPBDM')),
|
459 |
+
array('CAD', _x('Canadian Dollar (CAD)', 'admin settings', 'WPBDM')),
|
460 |
+
array('CZK', _x('Czech Koruna (CZK)', 'admin settings', 'WPBDM')),
|
461 |
+
array('DKK', _x('Danish Krone (DKK)', 'admin settings', 'WPBDM')),
|
462 |
+
array('EUR', _x('Euro (EUR)', 'admin settings', 'WPBDM')),
|
463 |
+
array('HKD', _x('Hong Kong Dollar (HKD)', 'admin settings', 'WPBDM')),
|
464 |
+
array('HUF', _x('Hungarian Forint (HUF)', 'admin settings', 'WPBDM')),
|
465 |
+
array('ILS', _x('Israeli New Shequel (ILS)', 'admin settings', 'WPBDM')),
|
466 |
+
array('JPY', _x('Japanese Yen (JPY)', 'admin settings', 'WPBDM')),
|
467 |
+
array('MYR', _x('Malasian Ringgit (MYR)', 'admin settings', 'WPBDM')),
|
468 |
+
array('MXN', _x('Mexican Peso (MXN)', 'admin settings', 'WPBDM')),
|
469 |
+
array('NOK', _x('Norwegian Krone (NOK)', 'admin settings', 'WPBDM')),
|
470 |
+
array('NZD', _x('New Zealand Dollar (NZD)', 'admin settings', 'WPBDM')),
|
471 |
+
array('PHP', _x('Philippine Peso (PHP)', 'admin settings', 'WPBDM')),
|
472 |
+
array('PLN', _x('Polish Zloty (PLN)', 'admin settings', 'WPBDM')),
|
473 |
+
array('GBP', _x('Pound Sterling (GBP)', 'admin settings', 'WPBDM')),
|
474 |
+
array('SGD', _x('Singapore Dollar (SGD)', 'admin settings', 'WPBDM')),
|
475 |
+
array('SEK', _x('Swedish Krona (SEK)', 'admin settings', 'WPBDM')),
|
476 |
+
array('CHF', _x('Swiss Franc (CHF)', 'admin settings', 'WPBDM')),
|
477 |
+
array('TWD', _x('Taiwan Dollar (TWD)', 'admin settings', 'WPBDM')),
|
478 |
+
array('THB', _x('Thai Baht (THB)', 'admin settings', 'WPBDM')),
|
479 |
+
array('TRY', _x('Turkish Lira (TRY)', 'admin settings', 'WPBDM')),
|
480 |
+
array('USD', _x('U.S. Dollar', 'admin settings', 'WPBDM')),
|
481 |
+
)));
|
482 |
+
$this->register_dep( 'currency', 'requires-true', 'payments-on' );
|
483 |
+
|
484 |
+
$this->add_setting($s, 'currency-symbol', _x('Currency Symbol', 'admin settings', 'WPBDM'), 'text', '$');
|
485 |
+
$this->register_dep( 'currency-symbol', 'requires-true', 'payments-on' );
|
486 |
+
|
487 |
+
$this->add_setting($s, 'payment-message', _x('Thank you for payment message', 'admin settings', 'WPBDM'), 'text',
|
488 |
+
_x('Thank you for your payment. Your payment is being verified and your listing reviewed. The verification and review process could take up to 48 hours.', 'admin settings', 'WPBDM'));
|
489 |
+
$this->register_dep( 'payment-message', 'requires-true', 'payments-on' );
|
490 |
+
|
491 |
+
/* Registration settings */
|
492 |
+
$g = $this->add_group('registration', _x('Registration', 'admin settings', 'WPBDM'));
|
493 |
+
$s = $this->add_section($g, 'registration', _x('Registration Settings', 'admin settings', 'WPBDM'));
|
494 |
+
$this->add_setting($s, 'require-login', _x('Require login?', 'admin settings', 'WPBDM'), 'boolean', true);
|
495 |
+
//$this->add_setting($s, 'login-url', _x('Login URL', 'admin settings', 'WPBDM'), 'text', wp_login_url()); // deprecated as of 2.1
|
496 |
+
// deprecated as of 2.1, added again for 3.4
|
497 |
+
$this->add_setting( $s,
|
498 |
+
'registration-url',
|
499 |
+
_x( 'Registration URL', 'admin settings', 'WPBDM' ),
|
500 |
+
'text',
|
501 |
+
'',
|
502 |
+
_x( 'URL of your membership plugin\'s registration page. Only enter this if using a membership plugin or custom registration page.', 'admin settings', 'WPBDM' ) );
|
503 |
+
|
504 |
+
/* Image settings */
|
505 |
+
$g = $this->add_group( 'image',
|
506 |
+
_x( 'Image', 'admin settings', 'WPBDM' ),
|
507 |
+
_x( 'Any changes to these settings will affect new listings only. Existing listings will not be affected. If you wish to change existing listings, you will need to re-upload the image(s) on that listing after changing things here.', 'admin settings', 'WPBDM' ) );
|
508 |
+
$s = $this->add_section($g, 'image', _x('Image Settings', 'admin settings', 'WPBDM'));
|
509 |
+
$this->add_setting($s, 'allow-images', _x('Allow images?', 'admin settings', 'WPBDM'), 'boolean', true);
|
510 |
+
$this->add_setting($s, 'image-max-filesize', _x('Max Image File Size (KB)', 'admin settings', 'WPBDM'), 'text', '10000');
|
511 |
+
// $this->add_setting($s, 'image-min-filesize', _x('Minimum Image File Size (KB)', 'admin settings', 'WPBDM'), 'text', '50');
|
512 |
+
$this->add_setting($s, 'image-max-width', _x('Max image width', 'admin settings', 'WPBDM'), 'text', '500');
|
513 |
+
$this->add_setting($s, 'image-max-height', _x('Max image height', 'admin settings', 'WPBDM'), 'text', '500');
|
514 |
+
$this->add_setting($s, 'thumbnail-width', _x('Thumbnail width', 'admin settings', 'WPBDM'), 'text', '150');
|
515 |
+
$this->add_setting( $s, 'use-thickbox', _x( 'Turn on thickbox/lightbox?', 'admin settings', 'WPBDM' ), 'boolean', false, _x( 'Uncheck if it conflicts with other elements or plugins installed on your site', 'admin settings', 'WPBDM' ) );
|
516 |
+
|
517 |
+
$s = $this->add_section($g, 'listings', _x('Listings', 'admin settings', 'WPBDM'));
|
518 |
+
$this->add_setting( $s,
|
519 |
+
'free-images',
|
520 |
+
_x( 'Number of free images', 'admin settings', 'WPBDM' ),
|
521 |
+
'text',
|
522 |
+
'2',
|
523 |
+
str_replace( '<a>',
|
524 |
+
'<a href="' . admin_url( 'admin.php?page=wpbdp_admin_fees' ) . '">',
|
525 |
+
_x( 'For paid listing images, configure that by adding or editing a <a>Fee Plan</a> instead of this setting, which is ignored for paid listings.', 'admin settings', 'WPBDM' ) ) );
|
526 |
+
$this->add_setting($s, 'use-default-picture', _x('Use default picture for listings with no picture?', 'admin settings', 'WPBDM'), 'boolean', true);
|
527 |
+
$this->add_setting($s, 'show-thumbnail', _x('Show Thumbnail on main listings page?', 'admin settings', 'WPBDM'), 'boolean', true);
|
528 |
+
}
|
529 |
+
|
530 |
+
public function quicksearch_fields_cb() {
|
531 |
+
$fields = array();
|
532 |
+
|
533 |
+
foreach ( wpbdp_get_form_fields( 'association=-custom' ) as $field ) {
|
534 |
+
$is_text_field = false;
|
535 |
+
|
536 |
+
if ( in_array( $field->get_association(), array( 'excerpt', 'content' ) ) || 'textarea' == $field->get_field_type_id() )
|
537 |
+
$is_text_field = true;
|
538 |
+
|
539 |
+
$fields[] = array( $field->get_id(), $field->get_label(), $is_text_field ? 'textfield' : '' );
|
540 |
+
}
|
541 |
+
|
542 |
+
return $fields;
|
543 |
+
}
|
544 |
+
|
545 |
+
public function sortbar_fields_cb() {
|
546 |
+
$fields = array();
|
547 |
+
|
548 |
+
foreach ( wpbdp_get_form_fields() as $f ) {
|
549 |
+
if ( in_array( $f->get_field_type_id(), array( 'textarea', 'select', 'checkbox', 'url' ), true ) ||
|
550 |
+
in_array( $f->get_association(), array( 'category', 'tags' ), true ) )
|
551 |
+
continue;
|
552 |
+
|
553 |
+
$fields[ $f->get_id() ] = $f->get_label();
|
554 |
+
}
|
555 |
+
|
556 |
+
$fields['user_login'] = 'User';
|
557 |
+
$fields['user_registered'] = 'User registration date';
|
558 |
+
$fields['date'] = 'Date posted';
|
559 |
+
$fields['modified'] = 'Date last modified';
|
560 |
+
|
561 |
+
return $fields;
|
562 |
+
}
|
563 |
+
|
564 |
+
public function _validate_listings_permalink($setting, $newvalue, $oldvalue=null) {
|
565 |
+
return trim(str_replace(' ', '', $newvalue));
|
566 |
+
}
|
567 |
+
|
568 |
+
public function _validate_term_permalink($setting, $newvalue, $oldvalue=null) {
|
569 |
+
$bd_taxonomy = $setting->name == 'permalinks-category-slug' ? WPBDP_CATEGORY_TAX : WPBDP_TAGS_TAX;
|
570 |
+
foreach (get_taxonomies(null, 'objects') as $taxonomy) {
|
571 |
+
if ($taxonomy->rewrite && $taxonomy->rewrite['slug'] == $newvalue && $taxonomy->name != $bd_taxonomy) {
|
572 |
+
return $oldvalue;
|
573 |
+
}
|
574 |
+
}
|
575 |
+
|
576 |
+
return trim(str_replace(' ', '', $newvalue));
|
577 |
+
}
|
578 |
+
|
579 |
+
public function _validate_listing_duration($setting, $newvalue, $oldvalue=null) {
|
580 |
+
// limit 'duration' because of TIMESTAMP limited range (issue #157).
|
581 |
+
// FIXME: this is not a long-term fix. we should move to DATETIME to avoid this entirely.
|
582 |
+
$v = min(max(intval($newvalue), 0), 3650);
|
583 |
+
return $v;
|
584 |
+
}
|
585 |
+
|
586 |
+
public function add_group($slug, $name, $help_text='') {
|
587 |
+
$group = new StdClass();
|
588 |
+
$group->wpslug = self::PREFIX . $slug;
|
589 |
+
$group->slug = $slug;
|
590 |
+
$group->name = esc_attr( $name );
|
591 |
+
$group->help_text = $help_text;
|
592 |
+
$group->sections = array();
|
593 |
+
|
594 |
+
$this->groups[$slug] = $group;
|
595 |
+
|
596 |
+
return $slug;
|
597 |
+
}
|
598 |
+
|
599 |
+
public function add_section($group_slug, $slug, $name, $help_text='') {
|
600 |
+
$section = new StdClass();
|
601 |
+
$section->name = esc_attr( $name );
|
602 |
+
$section->slug = $slug;
|
603 |
+
$section->help_text = $help_text;
|
604 |
+
$section->settings = array();
|
605 |
+
|
606 |
+
$this->groups[$group_slug]->sections[$slug] = $section;
|
607 |
+
|
608 |
+
return "$group_slug:$slug";
|
609 |
+
}
|
610 |
+
|
611 |
+
public function add_core_setting( $name, $default=null ) {
|
612 |
+
$setting = new StdClass();
|
613 |
+
$setting->name = $name;
|
614 |
+
$setting->label = '';
|
615 |
+
$setting->help_text = '';
|
616 |
+
$setting->default = $default;
|
617 |
+
$setting->type = 'core';
|
618 |
+
$setting->args = array();
|
619 |
+
$setting->validator = '';
|
620 |
+
|
621 |
+
if ( !isset( $this->settings[ $name ] ) ) {
|
622 |
+
$this->settings[ $name ] = $setting;
|
623 |
+
}
|
624 |
+
|
625 |
+
return true;
|
626 |
+
}
|
627 |
+
|
628 |
+
public function add_setting( $section_key, $name, $label, $type = 'text', $default = null, $help_text = '', $args = array(),
|
629 |
+
$validator = null, $callback = null ) {
|
630 |
+
|
631 |
+
if ( $type == 'core' )
|
632 |
+
return $this->add_core_setting( $name, $default );
|
633 |
+
|
634 |
+
list($group, $section) = explode(':', $section_key);
|
635 |
+
$args = !$args ? array() : $args;
|
636 |
+
|
637 |
+
if (!$group || !$section)
|
638 |
+
return false;
|
639 |
+
|
640 |
+
if ( isset($this->groups[$group]) && isset($this->groups[$group]->sections[$section]) ) {
|
641 |
+
$_default = $default;
|
642 |
+
if (is_null($_default)) {
|
643 |
+
switch ($type) {
|
644 |
+
case 'text':
|
645 |
+
case 'choice':
|
646 |
+
$_default = '';
|
647 |
+
break;
|
648 |
+
case 'boolean':
|
649 |
+
$_default = false;
|
650 |
+
break;
|
651 |
+
default:
|
652 |
+
$_default = null;
|
653 |
+
break;
|
654 |
+
}
|
655 |
+
}
|
656 |
+
|
657 |
+
$setting = new StdClass();
|
658 |
+
$setting->name = esc_attr( $name );
|
659 |
+
$setting->label = $label;
|
660 |
+
$setting->help_text = $help_text;
|
661 |
+
$setting->default = $_default;
|
662 |
+
$setting->type = $type;
|
663 |
+
$setting->args = $args;
|
664 |
+
$setting->validator = $validator;
|
665 |
+
$setting->callback = $callback;
|
666 |
+
|
667 |
+
$setup_cb = '_setting_' . $setting->type . '_setup';
|
668 |
+
if ( is_callable( array( $this, $setup_cb ) ) ) {
|
669 |
+
call_user_func_array( array( $this, $setup_cb ), array( &$setting ) );
|
670 |
+
}
|
671 |
+
|
672 |
+
$this->groups[$group]->sections[$section]->settings[$name] = $setting;
|
673 |
+
}
|
674 |
+
|
675 |
+
if (!isset($this->settings[$name])) {
|
676 |
+
$this->settings[$name] = $setting;
|
677 |
+
}
|
678 |
+
|
679 |
+
return $name;
|
680 |
+
}
|
681 |
+
|
682 |
+
public function register_dep( $setting, $dep, $arg = null ) {
|
683 |
+
if ( ! isset( $this->deps[ $setting ] ) )
|
684 |
+
$this->deps[ $setting ] = array();
|
685 |
+
|
686 |
+
$this->deps[ $setting ][ $dep ] = $arg;
|
687 |
+
}
|
688 |
+
|
689 |
+
public function get_dependencies( $args = array() ) {
|
690 |
+
$args = wp_parse_args( $args, array(
|
691 |
+
'setting' => null,
|
692 |
+
'type' => null
|
693 |
+
) );
|
694 |
+
extract( $args );
|
695 |
+
|
696 |
+
if ( $setting )
|
697 |
+
return isset( $this->deps[ $setting ] ) ? $this->deps[ $setting ] : array();
|
698 |
+
|
699 |
+
if ( $type ) {
|
700 |
+
$res = array();
|
701 |
+
|
702 |
+
foreach ( $this->deps as $s => $deps ) {
|
703 |
+
foreach ( $deps as $d => $a ) {
|
704 |
+
if ( $type == $d )
|
705 |
+
$res[ $s ] = $a;
|
706 |
+
}
|
707 |
+
}
|
708 |
+
}
|
709 |
+
|
710 |
+
return $this->deps;
|
711 |
+
}
|
712 |
+
|
713 |
+
function get_setting( $name ) {
|
714 |
+
if ( isset( $this->settings[ $name ] ) )
|
715 |
+
return $this->settings[ $name ];
|
716 |
+
|
717 |
+
return false;
|
718 |
+
}
|
719 |
+
|
720 |
+
public function get($name, $ifempty=null) {
|
721 |
+
$value = get_option(self::PREFIX . $name, null);
|
722 |
+
|
723 |
+
if (is_null($value)) {
|
724 |
+
$default_value = isset($this->settings[$name]) ? $this->settings[$name]->default : null;
|
725 |
+
|
726 |
+
if (is_null($default_value))
|
727 |
+
return $ifempty;
|
728 |
+
|
729 |
+
return $default_value;
|
730 |
+
}
|
731 |
+
|
732 |
+
if (!is_null($ifempty) && empty($value))
|
733 |
+
$value = $ifempty;
|
734 |
+
|
735 |
+
if ($this->settings[$name]->type == 'boolean') {
|
736 |
+
return (boolean) intval($value);
|
737 |
+
} elseif ( 'choice' == $this->settings[$name]->type && isset( $this->settings[$name]->args['multiple'] ) && $this->settings[$name]->args['multiple'] ) {
|
738 |
+
if ( ! $value )
|
739 |
+
return array();
|
740 |
+
}
|
741 |
+
|
742 |
+
return $value;
|
743 |
+
}
|
744 |
+
|
745 |
+
public function set($name, $value, $onlyknown=true) {
|
746 |
+
$name = strtolower($name);
|
747 |
+
|
748 |
+
if ($onlyknown && !isset($this->settings[$name]))
|
749 |
+
return false;
|
750 |
+
|
751 |
+
if (isset($this->settings[$name]) && $this->settings[$name]->type == 'boolean') {
|
752 |
+
$value = (boolean) intval($value);
|
753 |
+
}
|
754 |
+
|
755 |
+
// wpbdp_debug("Setting $name = $value");
|
756 |
+
update_option(self::PREFIX . $name, $value);
|
757 |
+
|
758 |
+
return true;
|
759 |
+
}
|
760 |
+
|
761 |
+
/* emulates get_wpbusdirman_config_options() in version 2.0 until
|
762 |
+
* all deprecated code has been ported. */
|
763 |
+
public function pre_2_0_compat_get_config_options() {
|
764 |
+
$legacy_options = array();
|
765 |
+
|
766 |
+
foreach ($this->pre_2_0_options() as $old_key => $new_key) {
|
767 |
+
$setting_value = $this->get($new_key);
|
768 |
+
|
769 |
+
if ($new_key == 'googlecheckout' || $new_key == 'paypal' || $new_key == '2checkout')
|
770 |
+
$setting_value = !$setting_value;
|
771 |
+
|
772 |
+
if ($this->settings[$new_key]->type == 'boolean') {
|
773 |
+
$setting_value = $setting_value == true ? 'yes' : 'no';
|
774 |
+
}
|
775 |
+
|
776 |
+
$legacy_options[$old_key] = $setting_value;
|
777 |
+
}
|
778 |
+
|
779 |
+
return $legacy_options;
|
780 |
+
}
|
781 |
+
|
782 |
+
|
783 |
+
|
784 |
+
public function reset_defaults() {
|
785 |
+
foreach ($this->settings as $setting) {
|
786 |
+
delete_option(self::PREFIX . $setting->name);
|
787 |
+
}
|
788 |
+
}
|
789 |
+
|
790 |
+
/*
|
791 |
+
* admin
|
792 |
+
*/
|
793 |
+
public function after_render( $html, $setting, $args = array() ) {
|
794 |
+
$html = '<a name="' . $setting->name . '"></a>' . $html;
|
795 |
+
return $html;
|
796 |
+
}
|
797 |
+
|
798 |
+
public function _setting_custom($args) {
|
799 |
+
$setting = $args['setting'];
|
800 |
+
$value = $this->get( $setting->name );
|
801 |
+
|
802 |
+
$html = '';
|
803 |
+
|
804 |
+
ob_start();
|
805 |
+
call_user_func( $setting->callback, $setting, $value );
|
806 |
+
$custom_content = ob_get_contents();
|
807 |
+
ob_end_clean();
|
808 |
+
|
809 |
+
$html .= $custom_content;
|
810 |
+
|
811 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
812 |
+
}
|
813 |
+
|
814 |
+
public function _setting_text($args) {
|
815 |
+
$setting = $args['setting'];
|
816 |
+
$value = $this->get($setting->name);
|
817 |
+
|
818 |
+
if (isset($args['use_textarea']) || strlen($value) > 100) {
|
819 |
+
$html = '<textarea id="' . $setting->name . '" name="' . self::PREFIX . $setting->name . '" rows="' . ( isset( $args['textarea_rows'] ) ? $args['textarea_rows'] : 4 ) . '">';
|
820 |
+
$html .= esc_textarea($value);
|
821 |
+
$html .= '</textarea><br />';
|
822 |
+
} else {
|
823 |
+
$html = '<input type="text" id="' . $setting->name . '" name="' . self::PREFIX . $setting->name . '" value="' . esc_attr( $value ) . '" size="' . (strlen($value) > 0 ? strlen($value) : 20). '" />';
|
824 |
+
}
|
825 |
+
|
826 |
+
$html .= '<span class="description">' . $setting->help_text . '</span>';
|
827 |
+
|
828 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
829 |
+
}
|
830 |
+
|
831 |
+
public function _setting_license_key($args) {
|
832 |
+
$setting = $args['setting'];
|
833 |
+
$value = trim( $this->get( $setting->name ) );
|
834 |
+
|
835 |
+
$module_id = str_replace( 'license-key-', '', $setting->name );
|
836 |
+
$license_status = get_option( 'wpbdp-license-status-' . $module_id, false );
|
837 |
+
|
838 |
+
$html = '';
|
839 |
+
$html .= '<input type="text"
|
840 |
+
id="' . $setting->name . '"
|
841 |
+
name="' . self::PREFIX . $setting->name . '"
|
842 |
+
value="' . esc_attr( $value ) . '"
|
843 |
+
size="25"
|
844 |
+
' . ( 'valid' == $license_status ? 'readonly="readonly"' : '' ) . '/>';
|
845 |
+
|
846 |
+
if ( $value ) {
|
847 |
+
$html .= '<span class="license-activation" data-module-id="' . esc_attr( $module_id ) . '">';
|
848 |
+
$html .= wp_nonce_field( 'license activation', 'nonce', false, false );
|
849 |
+
$html .= '<input type="button"
|
850 |
+
value="' . _x( 'Deactivate License', 'settings', 'WPBDM' ) . '"
|
851 |
+
class="button-secondary license-deactivate"
|
852 |
+
data-L10n="' . esc_attr( _x( 'Deactivating license...', 'settings', 'WPBDM' ) ) . '"
|
853 |
+
style="' . ( 'valid' == $license_status ? '' : 'display: none;' ) . '" />';
|
854 |
+
$html .= '<input type="button"
|
855 |
+
value="' . _x( 'Activate License', 'settings', 'WPBDM' ) . '"
|
856 |
+
class="button-secondary license-activate"
|
857 |
+
data-L10n="' . esc_attr( _x( 'Activating license...', 'settings', 'WPBDM' ) ) . '"
|
858 |
+
style="' . ( 'valid' == $license_status ? 'display: none;' : '' ) . '" />';
|
859 |
+
$html .= '<br />';
|
860 |
+
$html .= '<span class="status-message"></span>';
|
861 |
+
$html .= '</span>';
|
862 |
+
}
|
863 |
+
|
864 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
865 |
+
}
|
866 |
+
|
867 |
+
public function _setting_text_template( $args ) {
|
868 |
+
$setting = $args['setting'];
|
869 |
+
$help_text_original = $setting->help_text;
|
870 |
+
|
871 |
+
$placeholders = isset( $args['placeholders'] ) ? $args['placeholders'] : array();
|
872 |
+
|
873 |
+
if ( $placeholders ) {
|
874 |
+
$placeholders_text = '';
|
875 |
+
|
876 |
+
foreach ( $placeholders as $pholder => $desc ) {
|
877 |
+
$placeholders_text .= sprintf( '%s - %s, ', '[' . $pholder . ']', $desc );
|
878 |
+
}
|
879 |
+
$placeholders_text = substr( $placeholders_text, 0, -2 ) . '.';
|
880 |
+
|
881 |
+
$setting->help_text = sprintf( _x( 'Valid placeholders: %s', 'admin settings', 'WPBDM' ),
|
882 |
+
$placeholders_text );
|
883 |
+
}
|
884 |
+
|
885 |
+
$args['use_textarea'] = true;
|
886 |
+
|
887 |
+
// TODO: this is a proxy for _setting_text (for now).
|
888 |
+
ob_start();
|
889 |
+
$this->_setting_text( $args );
|
890 |
+
$html = ob_get_contents();
|
891 |
+
ob_end_clean();
|
892 |
+
|
893 |
+
$setting->help_text = $help_text_original;
|
894 |
+
|
895 |
+
echo $html;
|
896 |
+
}
|
897 |
+
|
898 |
+
function _setting_email_template( $args ) {
|
899 |
+
$setting = $args['setting'];
|
900 |
+
$value = $this->get( $setting->name );
|
901 |
+
|
902 |
+
if ( ! is_array( $value ) ) {
|
903 |
+
$body = $value;
|
904 |
+
|
905 |
+
$value = array();
|
906 |
+
$value['subject'] = $setting->default['subject'];
|
907 |
+
$value['body'] = $body;
|
908 |
+
}
|
909 |
+
|
910 |
+
$html = '';
|
911 |
+
$html .= '<span class="description">' . $setting->help_text . '</span>';
|
912 |
+
$html .= sprintf( '<div class="wpbdp-settings-email" data-setting="%s">',
|
913 |
+
$setting->name );
|
914 |
+
|
915 |
+
$html .= '<div class="short-preview" title="' . _x( 'Click to edit e-mail', 'settings email', 'WPBDM' ) . '">';
|
916 |
+
$html .= '<span class="edit-toggle tag">' . _x( 'Click to edit', 'settings email', 'WPBDM' ) . '</span>';
|
917 |
+
$html .= '<h4>';
|
918 |
+
$html .= $value['subject'];
|
919 |
+
$html .= '</h4>';
|
920 |
+
$html .= $value['body'];
|
921 |
+
$html .= '...';
|
922 |
+
$html .= '</div>';
|
923 |
+
|
924 |
+
$html .= sprintf( '<div class="editor" style="display: none;" data-preview-nonce="%s">', wp_create_nonce( 'preview email ' . $setting->name ) );
|
925 |
+
$html .= '<table class="form-table"><tbody>';
|
926 |
+
$html .= '<tr>';
|
927 |
+
$html .= sprintf( '<th scope="row"><label for="%s-subject">%s</label</th>',
|
928 |
+
$setting->name,
|
929 |
+
_x( 'E-Mail Subject', 'settings email', 'WPBDM' ) );
|
930 |
+
$html .= '<td>';
|
931 |
+
$html .= sprintf( '<input type="text" name="%s" value="%s" id="%s" class="subject-text">',
|
932 |
+
self::PREFIX . $setting->name . '[subject]',
|
933 |
+
esc_attr( $value['subject'] ),
|
934 |
+
$setting->name . '-subject' );
|
935 |
+
$html .= '</td>';
|
936 |
+
$html .= '</tr>';
|
937 |
+
$html .= '<tr>';
|
938 |
+
$html .= sprintf( '<th scope="row"><label for="%s-body">%s</label</th>',
|
939 |
+
$setting->name,
|
940 |
+
_x( 'E-Mail Body', 'settings email', 'WPBDM' ) );
|
941 |
+
$html .= '<td>';
|
942 |
+
$html .= sprintf( '<textarea id="%s" name="%s" class="body-text">%s</textarea>',
|
943 |
+
$setting->name . '-body',
|
944 |
+
self::PREFIX . $setting->name . '[body]',
|
945 |
+
esc_textarea( $value['body'] ) );
|
946 |
+
|
947 |
+
$placeholders = isset( $args['placeholders'] ) ? $args['placeholders'] : array();
|
948 |
+
|
949 |
+
if ( $placeholders ) {
|
950 |
+
$html .= '<div class="placeholders">';
|
951 |
+
$html .= _x( 'You can use the following placeholders:', 'settings email', 'WPBDM' );
|
952 |
+
$html .= '<br /><br />';
|
953 |
+
|
954 |
+
$added_sep = false;
|
955 |
+
|
956 |
+
foreach ( $placeholders as $placeholder => $placeholder_data ) {
|
957 |
+
$description = is_array( $placeholder_data ) ? $placeholder_data[0] : $placeholder_data;
|
958 |
+
$is_core_placeholder = is_array( $placeholder_data ) && isset( $placeholder_data[2] ) && $placeholder_data[2];
|
959 |
+
|
960 |
+
if ( $is_core_placeholder && ! $added_sep ) {
|
961 |
+
$html .= '<div class="placeholder-separator"></div>';
|
962 |
+
$added_sep = true;
|
963 |
+
}
|
964 |
+
|
965 |
+
$html .= sprintf( '<div class="placeholder" data-placeholder="%s"><span class="placeholder-code">[%s]</span> - <span class="placeholder-description">%s</span></div>',
|
966 |
+
esc_attr( $placeholder ),
|
967 |
+
$placeholder,
|
968 |
+
$description );
|
969 |
+
}
|
970 |
+
$html .= '</div>';
|
971 |
+
}
|
972 |
+
|
973 |
+
$html .= '<div class="buttons">';
|
974 |
+
$html .= '<a href="#" class="button preview-email">' . _x( 'Preview e-mail', 'settings email', 'WPBDM' ) . '</a> ';
|
975 |
+
$html .= '<a href="#" class="button cancel">' . _x( 'Cancel', 'settings email', 'WPBDM' ) . '</a> ';
|
976 |
+
$html .= '<a href="#" class="button button-primary save">' . _x( 'Save Changes', 'settings email', 'WPBDM' ) . '</a> ';
|
977 |
+
$html .= '</div>';
|
978 |
+
|
979 |
+
$html .= '</td>';
|
980 |
+
$html .= '</tr>';
|
981 |
+
$html .= '</tbody></table>';
|
982 |
+
$html .= '</div>';
|
983 |
+
|
984 |
+
$html .= '</div>';
|
985 |
+
|
986 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
987 |
+
}
|
988 |
+
|
989 |
+
function _setting_email_template_setup( &$setting ) {
|
990 |
+
if ( ! isset( $setting->args['placeholders'] ) || ! is_array( $setting->args['placeholders'] ) )
|
991 |
+
$setting->args['placeholders'] = array();
|
992 |
+
|
993 |
+
// Add default placeholders.
|
994 |
+
$setting->args['placeholders'] = array_merge( $setting->args['placeholders'], array(
|
995 |
+
'site-title' => array( _x( 'Site title', 'settings email', 'WPBDM' ),
|
996 |
+
get_bloginfo( 'name' ),
|
997 |
+
'core' ),
|
998 |
+
'site-link' => array( _x( 'Site title (with link)', 'settings email', 'WPBDM' ),
|
999 |
+
sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'name' ) ),
|
1000 |
+
'core' ),
|
1001 |
+
'site-url' => array( _x( 'Site address (with link)', 'settings email', 'WPBDM' ),
|
1002 |
+
sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'url' ) ),
|
1003 |
+
'core' ),
|
1004 |
+
'directory-url' => array( _x( 'Directory URL (with link)', 'settings email', 'WPBDM' ),
|
1005 |
+
sprintf( '<a href="%1$s">%1$s</a>', wpbdp_get_page_link( 'main' ) ),
|
1006 |
+
'core' ),
|
1007 |
+
'today' => array( _x( 'Current date', 'settings email', 'WPBDM' ),
|
1008 |
+
date_i18n( get_option( 'date_format' ) ),
|
1009 |
+
'core' ),
|
1010 |
+
'now' => array( _x( 'Current time', 'settings email', 'WPBDM' ),
|
1011 |
+
date_i18n( get_option( 'time_format' ) ),
|
1012 |
+
'core' )
|
1013 |
+
) );
|
1014 |
+
}
|
1015 |
+
|
1016 |
+
function _ajax_email_preview() {
|
1017 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
1018 |
+
$setting = $this->get_setting( isset( $_POST['setting'] ) ? $_POST['setting'] : '' );
|
1019 |
+
|
1020 |
+
if ( ! $setting || 'email_template' != $setting->type || ! wp_verify_nonce( $nonce, 'preview email ' . $setting->name ) )
|
1021 |
+
die();
|
1022 |
+
|
1023 |
+
$placeholders = isset( $setting->args['placeholders'] ) ? $setting->args['placeholders'] : array();
|
1024 |
+
|
1025 |
+
$subject = stripslashes( isset( $_POST['subject'] ) ? trim( $_POST['subject'] ) : '' );
|
1026 |
+
$body = stripslashes( isset( $_POST['body'] ) ? trim( $_POST['body'] ) : '' );
|
1027 |
+
|
1028 |
+
$res = new WPBDP_Ajax_Response();
|
1029 |
+
|
1030 |
+
foreach ( $placeholders as $pholder => $pdata ) {
|
1031 |
+
$repl = ( is_array( $pdata ) && count( $pdata ) >= 2 && $pdata[1] ) ? $pdata[1] : '[' . $pholder . ']';
|
1032 |
+
|
1033 |
+
$subject = str_replace( '[' . $pholder . ']', $repl, $subject );
|
1034 |
+
$body = str_replace( '[' . $pholder . ']', $repl, $body );
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
$html = '';
|
1038 |
+
$html .= '<div class="wpbdp-settings-email-preview">';
|
1039 |
+
$html .= '<h4>' . $subject . '</h4>';
|
1040 |
+
$html .= nl2br( $body );
|
1041 |
+
$html .= '</div>';
|
1042 |
+
|
1043 |
+
$res->add( 'subject', $subject );
|
1044 |
+
$res->add( 'body', $body );
|
1045 |
+
$res->add( 'html', $html );
|
1046 |
+
$res->send();
|
1047 |
+
}
|
1048 |
+
|
1049 |
+
public function _setting_boolean($args) {
|
1050 |
+
$setting = $args['setting'];
|
1051 |
+
|
1052 |
+
$value = (boolean) $this->get($setting->name);
|
1053 |
+
|
1054 |
+
$html = '<label for="' . $setting->name . '">';
|
1055 |
+
$html .= '<input type="checkbox" id="' .$setting->name . '" name="' . self::PREFIX . $setting->name . '" value="1" '
|
1056 |
+
. ($value ? 'checked="checked"' : '') . '/>';
|
1057 |
+
$html .= ' <span class="description">' . $setting->help_text . '</span>';
|
1058 |
+
$html .= '</label>';
|
1059 |
+
|
1060 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
public function _setting_choice($args) {
|
1064 |
+
$setting = $args['setting'];
|
1065 |
+
$choices = is_callable( $args['choices'] ) ? call_user_func( $args['choices'] ) : $args['choices'];
|
1066 |
+
|
1067 |
+
$value = $this->get($setting->name);
|
1068 |
+
|
1069 |
+
$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
|
1070 |
+
$widget = $multiple ? ( isset( $args['use_checkboxes'] ) && $args['use_checkboxes'] ? 'checkbox' : 'multiselect' ) : 'select'; // TODO: Add support for radios.
|
1071 |
+
|
1072 |
+
if ( 'multiselect' == $widget )
|
1073 |
+
$multiple = true;
|
1074 |
+
|
1075 |
+
$html = '';
|
1076 |
+
|
1077 |
+
if ( $widget == 'select' || $widget == 'multiselect' ) {
|
1078 |
+
$html .= '<select id="' . $setting->name . '" name="' . self::PREFIX . $setting->name . ( $multiple ? '[]' : '' ) . '" ' . ( $multiple ? 'multiple="multiple"' : '' ) . '>';
|
1079 |
+
|
1080 |
+
$value = is_array( $value ) ? $value : array( $value );
|
1081 |
+
|
1082 |
+
foreach ($choices as $ch) {
|
1083 |
+
$opt_label = is_array($ch) ? $ch[1] : $ch;
|
1084 |
+
$opt_value = is_array($ch) ? $ch[0] : $ch;
|
1085 |
+
$opt_class = ( is_array( $ch ) && isset( $ch[2] ) ) ? $ch[2] : '';
|
1086 |
+
|
1087 |
+
$html .= '<option value="' . $opt_value . '"' . ( $value && in_array( $opt_value, $value ) ? ' selected="selected"' : '') . ' class="' . $opt_class . '">'
|
1088 |
+
. $opt_label . '</option>';
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
$html .= '</select>';
|
1092 |
+
} elseif ( $widget == 'checkbox' ) {
|
1093 |
+
foreach ( $choices as $k => $v ) {
|
1094 |
+
$html .= sprintf( '<label><input type="checkbox" name="%s[]" value="%s" %s />%s</label><br />',
|
1095 |
+
self::PREFIX . $setting->name,
|
1096 |
+
$k,
|
1097 |
+
( $value && in_array( $k, $value ) ) ? 'checked="checked"' : '',
|
1098 |
+
$v );
|
1099 |
+
}
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
$html .= '<span class="description">' . $setting->help_text . '</span>';
|
1103 |
+
|
1104 |
+
echo apply_filters( 'wpbdp_settings_render', $html, $setting, $args );
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
public function register_in_admin() {
|
1108 |
+
foreach ($this->groups as $group) {
|
1109 |
+
foreach ($group->sections as $section) {
|
1110 |
+
$callback = create_function('', 'echo "<a name=\"' . $section->slug . '\"></a>";');
|
1111 |
+
|
1112 |
+
if ($section->help_text)
|
1113 |
+
$callback = create_function('', 'echo "<p class=\"description\">' . addslashes( $section->help_text ) . '</p>";');
|
1114 |
+
|
1115 |
+
add_settings_section($section->slug, $section->name, $callback, $group->wpslug);
|
1116 |
+
|
1117 |
+
foreach ($section->settings as $setting) {
|
1118 |
+
register_setting($group->wpslug, self::PREFIX . $setting->name/*, array( &$this, 'filter_x' ) */);
|
1119 |
+
add_settings_field(self::PREFIX . $setting->name, $setting->label,
|
1120 |
+
array($this, '_setting_' . $setting->type),
|
1121 |
+
$group->wpslug,
|
1122 |
+
$section->slug,
|
1123 |
+
array_merge($setting->args, array('label_for' => $setting->name, 'setting' => $setting))
|
1124 |
+
);
|
1125 |
+
|
1126 |
+
if ( $setting->validator || ( $setting->type == 'choice' && isset( $setting->args['multiple'] ) && $setting->args['multiple'] ) ) {
|
1127 |
+
add_filter('pre_update_option_' . self::PREFIX . $setting->name, create_function('$n, $o=null', 'return WPBDP_Settings::_validate_setting("' . $setting->name . '", $n, $o);'), 10, 2);
|
1128 |
+
}
|
1129 |
+
}
|
1130 |
+
}
|
1131 |
+
}
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
public static function _validate_setting($name, $newvalue=null, $oldvalue=null) {
|
1135 |
+
$api = wpbdp_settings_api();
|
1136 |
+
$setting = $api->settings[$name];
|
1137 |
+
|
1138 |
+
if ( $setting->type == 'choice' && isset( $setting->args['multiple'] ) && $setting->args['multiple'] ) {
|
1139 |
+
if ( isset( $_POST[ self::PREFIX . $name ] ) ) {
|
1140 |
+
$newvalue = $_POST[ self::PREFIX . $name ];
|
1141 |
+
$newvalue = is_array( $newvalue ) ? $newvalue : array( $newvalue );
|
1142 |
+
|
1143 |
+
if ( $setting->validator )
|
1144 |
+
$newvalue = call_user_func( $setting->validator, $setting, $newvalue, $api->get( $setting->name ) );
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
return $newvalue;
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
return call_user_func($setting->validator, $setting, $newvalue, $api->get($setting->name));
|
1151 |
+
}
|
1152 |
+
|
1153 |
+
/* upgrade from old-style settings to new options */
|
1154 |
+
public function pre_2_0_options() {
|
1155 |
+
static $option_translations = array(
|
1156 |
+
'wpbusdirman_settings_config_18' => 'listing-duration',
|
1157 |
+
/* 'wpbusdirman_settings_config_25' => 'hide-buy-module-buttons',*/ /* removed in 2.0 */
|
1158 |
+
'wpbusdirman_settings_config_26' => 'hide-tips',
|
1159 |
+
'wpbusdirman_settings_config_27' => 'show-contact-form',
|
1160 |
+
'wpbusdirman_settings_config_36' => 'show-comment-form',
|
1161 |
+
'wpbusdirman_settings_config_34' => 'credit-author',
|
1162 |
+
'wpbusdirman_settings_config_38' => 'listing-renewal',
|
1163 |
+
'wpbusdirman_settings_config_39' => 'use-default-picture',
|
1164 |
+
'wpbusdirman_settings_config_44' => 'show-listings-under-categories',
|
1165 |
+
'wpbusdirman_settings_config_45' => 'override-email-blocking',
|
1166 |
+
'wpbusdirman_settings_config_46' => 'status-on-uninstall',
|
1167 |
+
'wpbusdirman_settings_config_47' => 'deleted-status',
|
1168 |
+
'wpbusdirman_settings_config_3' => 'require-login',
|
1169 |
+
'wpbusdirman_settings_config_4' => 'login-url',
|
1170 |
+
'wpbusdirman_settings_config_5' => 'registration-url',
|
1171 |
+
'wpbusdirman_settings_config_1' => 'new-post-status',
|
1172 |
+
'wpbusdirman_settings_config_19' => 'edit-post-status',
|
1173 |
+
'wpbusdirman_settings_config_7' => 'categories-order-by',
|
1174 |
+
'wpbusdirman_settings_config_8' => 'categories-sort',
|
1175 |
+
'wpbusdirman_settings_config_9' => 'show-category-post-count',
|
1176 |
+
'wpbusdirman_settings_config_10' => 'hide-empty-categories',
|
1177 |
+
'wpbusdirman_settings_config_48' => 'show-only-parent-categories',
|
1178 |
+
'wpbusdirman_settings_config_52' => 'listings-order-by',
|
1179 |
+
'wpbusdirman_settings_config_53' => 'listings-sort',
|
1180 |
+
'wpbusdirman_settings_config_6' => 'allow-images',
|
1181 |
+
'wpbusdirman_settings_config_2' => 'free-images',
|
1182 |
+
'wpbusdirman_settings_config_11' => 'show-thumbnail',
|
1183 |
+
'wpbusdirman_settings_config_13' => 'image-max-filesize',
|
1184 |
+
'wpbusdirman_settings_config_14' => 'image-min-filesize',
|
1185 |
+
'wpbusdirman_settings_config_15' => 'image-max-width',
|
1186 |
+
'wpbusdirman_settings_config_16' => 'image-max-height',
|
1187 |
+
'wpbusdirman_settings_config_17' => 'thumbnail-width',
|
1188 |
+
'wpbusdirman_settings_config_20' => 'currency',
|
1189 |
+
'wpbusdirman_settings_config_12' => 'currency-symbol',
|
1190 |
+
'wpbusdirman_settings_config_21' => 'payments-on',
|
1191 |
+
'wpbusdirman_settings_config_22' => 'payments-test-mode',
|
1192 |
+
'wpbusdirman_settings_config_37' => 'payment-message',
|
1193 |
+
'wpbusdirman_settings_config_23' => 'googlecheckout-merchant',
|
1194 |
+
'wpbusdirman_settings_config_24' => 'googlecheckout-seller',
|
1195 |
+
'wpbusdirman_settings_config_40' => 'googlecheckout',
|
1196 |
+
'wpbusdirman_settings_config_35' => 'paypal-business-email',
|
1197 |
+
'wpbusdirman_settings_config_41' => 'paypal',
|
1198 |
+
'wpbusdirman_settings_config_42' => '2checkout-seller',
|
1199 |
+
'wpbusdirman_settings_config_43' => '2checkout',
|
1200 |
+
'wpbusdirman_settings_config_31' => 'featured-on',
|
1201 |
+
'wpbusdirman_settings_config_32' => 'featured-price',
|
1202 |
+
'wpbusdirman_settings_config_33' => 'featured-description',
|
1203 |
+
'wpbusdirman_settings_config_28' => 'recaptcha-public-key',
|
1204 |
+
'wpbusdirman_settings_config_29' => 'recaptcha-private-key',
|
1205 |
+
'wpbusdirman_settings_config_30' => 'recaptcha-on',
|
1206 |
+
'wpbusdirman_settings_config_49' => 'permalinks-directory-slug',
|
1207 |
+
'wpbusdirman_settings_config_50' => 'permalinks-category-slug',
|
1208 |
+
'wpbusdirman_settings_config_51' => 'permalinks-tags-slug'
|
1209 |
+
);
|
1210 |
+
return $option_translations;
|
1211 |
+
}
|
1212 |
+
|
1213 |
+
public function upgrade_options() {
|
1214 |
+
if (!$this->settings)
|
1215 |
+
$this->_register_settings();
|
1216 |
+
|
1217 |
+
$translations = $this->pre_2_0_options();
|
1218 |
+
|
1219 |
+
if ($old_options = get_option('wpbusdirman_settings_config')) {
|
1220 |
+
foreach ($old_options as $option) {
|
1221 |
+
$id = strtolower($option['id']);
|
1222 |
+
$type = strtolower($option['type']);
|
1223 |
+
$value = $option['std'];
|
1224 |
+
|
1225 |
+
if ($type == 'titles' || $id == 'wpbusdirman_settings_config_25' || empty($value))
|
1226 |
+
continue;
|
1227 |
+
|
1228 |
+
if ($id == 'wpbusdirman_settings_config_40') {
|
1229 |
+
$this->set('googlecheckout', $value == 'yes' ? false : true);
|
1230 |
+
} elseif ($id == 'wpbusdirman_settings_config_41') {
|
1231 |
+
$this->set('paypal', $value == 'yes' ? false : true);
|
1232 |
+
} elseif ($id == 'wpbusdirman_settings_config_43') {
|
1233 |
+
$this->set('2checkout', $value == 'yes' ? false : true);
|
1234 |
+
} else {
|
1235 |
+
if (!isset($this->settings[$translations[$id]]))
|
1236 |
+
continue;
|
1237 |
+
|
1238 |
+
$newsetting = $this->settings[$translations[$id]];
|
1239 |
+
|
1240 |
+
switch ($newsetting->type) {
|
1241 |
+
case 'boolean':
|
1242 |
+
$this->set($newsetting->name, $value == 'yes' ? true : false);
|
1243 |
+
break;
|
1244 |
+
case 'choice':
|
1245 |
+
case 'text':
|
1246 |
+
default:
|
1247 |
+
$this->set($newsetting->name, $value);
|
1248 |
+
break;
|
1249 |
+
}
|
1250 |
+
}
|
1251 |
+
|
1252 |
+
}
|
1253 |
+
|
1254 |
+
delete_option('wpbusdirman_settings_config');
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
|
core/class-view.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Views (pages) API.
|
4 |
+
*/
|
5 |
+
|
6 |
+
abstract class WPBDP_View {
|
7 |
+
|
8 |
+
public function get_page_name() {
|
9 |
+
$clsname = get_class( $this );
|
10 |
+
return ltrim( strtolower( str_replace( array( 'WPBDP', '_', '-Page' ), array( '', '-', '' ), $clsname ) ), '-' );
|
11 |
+
}
|
12 |
+
|
13 |
+
public function get_title() {
|
14 |
+
return '';
|
15 |
+
}
|
16 |
+
|
17 |
+
public function dispatch() {
|
18 |
+
return '';
|
19 |
+
}
|
20 |
+
|
21 |
+
}
|
core/class-wpbdp.php
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP {
|
4 |
+
}
|
5 |
+
|
6 |
+
?>
|
core/compatibility/class-compat.php
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once ( WPBDP_PATH . 'core/compatibility/deprecated.php' );
|
3 |
+
|
4 |
+
class WPBDP_Compat {
|
5 |
+
|
6 |
+
function __construct() {
|
7 |
+
add_action( 'wpbdp_loaded', array( &$this, 'load_integrations' ) );
|
8 |
+
}
|
9 |
+
|
10 |
+
function load_integrations() {
|
11 |
+
if ( isset( $GLOBALS['sitepress'] ) ) {
|
12 |
+
require_once( WPBDP_PATH . 'core/compatibility/class-wpml-compat.php' );
|
13 |
+
$wpml_integration = new WPBDP_WPML_Compat();
|
14 |
+
}
|
15 |
+
}
|
16 |
+
|
17 |
+
}
|
core/compatibility/class-wpml-compat.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_WPML_Compat {
|
4 |
+
|
5 |
+
private $wpml;
|
6 |
+
|
7 |
+
function __construct() {
|
8 |
+
$this->wpml = $GLOBALS['sitepress'];
|
9 |
+
|
10 |
+
if ( ! is_admin() ) {
|
11 |
+
add_filter( 'wpbdp_get_page_id', array( &$this, 'page_id'), 10, 2 );
|
12 |
+
add_filter( 'wpbdp_listing_link', array( &$this, 'add_lang_to_link' ) );
|
13 |
+
add_filter( 'wpbdp_category_link', array( &$this, 'add_lang_to_link' ) );
|
14 |
+
add_filter( 'wpbdp_get_page_link', array( &$this, 'correct_page_link' ), 10, 3 );
|
15 |
+
|
16 |
+
add_filter( 'wpbdp_render_field_label', array( &$this, 'translate_form_field_label' ), 10, 2 );
|
17 |
+
add_filter( 'wpbdp_render_field_description', array( &$this, 'translate_form_field_description' ), 10, 2 );
|
18 |
+
add_filter( 'wpbdp_display_field_label', array( &$this, 'translate_form_field_label' ), 10, 2 );
|
19 |
+
|
20 |
+
add_filter( 'wpbdp_category_fee_selection_label', array( &$this, 'translate_fee_label' ), 10, 2 );
|
21 |
+
}
|
22 |
+
|
23 |
+
add_action( 'admin_footer-directory-admin_page_wpbdp_admin_formfields', array( &$this, 'register_form_fields_strings' ) );
|
24 |
+
add_action( 'admin_footer-directory-admin_page_wpbdp_admin_fees', array( &$this, 'register_fees_strings' ) );
|
25 |
+
}
|
26 |
+
|
27 |
+
function get_current_language() {
|
28 |
+
return $this->wpml->get_current_language();
|
29 |
+
}
|
30 |
+
|
31 |
+
function page_id( $id, $page_name = '' ) {
|
32 |
+
$lang = $this->get_current_language();
|
33 |
+
|
34 |
+
if ( ! $lang )
|
35 |
+
return $id;
|
36 |
+
|
37 |
+
$trans_id = icl_object_id( $id, 'page', false, $lang );
|
38 |
+
if ( ! $trans_id )
|
39 |
+
return $id;
|
40 |
+
|
41 |
+
return $trans_id;
|
42 |
+
}
|
43 |
+
|
44 |
+
function add_lang_to_link( $link ) {
|
45 |
+
$lang = $this->get_current_language();
|
46 |
+
|
47 |
+
if ( ! $lang )
|
48 |
+
return $link;
|
49 |
+
|
50 |
+
$link = add_query_arg( 'lang', $lang, $link );
|
51 |
+
return $link;
|
52 |
+
}
|
53 |
+
|
54 |
+
function correct_page_link( $link, $name = '', $arg0 = '' ) {
|
55 |
+
$lang = $this->get_current_language();
|
56 |
+
|
57 |
+
if ( ! $lang )
|
58 |
+
return $link;
|
59 |
+
|
60 |
+
switch ( $name ) {
|
61 |
+
case 'editlisting':
|
62 |
+
case 'upgradetostickylisting':
|
63 |
+
case 'deletelisting':
|
64 |
+
$link = add_query_arg( 'lang', $lang, $link );
|
65 |
+
break;
|
66 |
+
|
67 |
+
default:
|
68 |
+
break;
|
69 |
+
}
|
70 |
+
|
71 |
+
return $link;
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
function translate_link( $link ) {
|
76 |
+
$lang = $this->get_current_language();
|
77 |
+
|
78 |
+
if ( ! $lang )
|
79 |
+
return $link;
|
80 |
+
|
81 |
+
if ( wpbdp_rewrite_on() ) {
|
82 |
+
$main_id = wpbdp_get_page_id( 'main' );
|
83 |
+
$trans_id = icl_object_id( $main_id, 'page', false, $lang );
|
84 |
+
|
85 |
+
if ( ! $trans_id )
|
86 |
+
return $link;
|
87 |
+
|
88 |
+
$link = str_replace( _get_page_link( $main_id ), _get_page_link( $trans_id ), $link );
|
89 |
+
$link = add_query_arg( 'lang', $lang, $link );
|
90 |
+
} else {
|
91 |
+
$link = add_query_arg( 'lang', $lang, $link );
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
return $link;
|
96 |
+
}
|
97 |
+
|
98 |
+
// {{{ Form Fields integration.
|
99 |
+
|
100 |
+
function register_form_fields_strings() {
|
101 |
+
if ( isset( $_GET['action'] ) || ! function_exists( 'icl_register_string' ) )
|
102 |
+
return;
|
103 |
+
|
104 |
+
$fields = wpbdp_get_form_fields();
|
105 |
+
|
106 |
+
foreach ( $fields as &$f ) {
|
107 |
+
icl_register_string( 'Business Directory Plugin',
|
108 |
+
sprintf( 'Field #%d - label', $f->get_id() ),
|
109 |
+
$f->get_label() );
|
110 |
+
|
111 |
+
if ( $f->get_description() )
|
112 |
+
icl_register_string( 'Business Directory Plugin',
|
113 |
+
sprintf( 'Field #%d - description', $f->get_id() ),
|
114 |
+
$f->get_description() );
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
function translate_form_field_label( $label, $field ) {
|
119 |
+
if ( ! is_object( $field ) || ! function_exists( 'icl_t' ) )
|
120 |
+
return $label;
|
121 |
+
|
122 |
+
return icl_t( 'Business Directory Plugin',
|
123 |
+
sprintf( 'Field #%d - label', $field->get_id() ),
|
124 |
+
$field->get_label() );
|
125 |
+
}
|
126 |
+
|
127 |
+
function translate_form_field_description( $description, $field ) {
|
128 |
+
if ( ! is_object( $field ) || ! function_exists( 'icl_t' ) )
|
129 |
+
return $description;
|
130 |
+
|
131 |
+
return icl_t( 'Business Directory Plugin',
|
132 |
+
sprintf( 'Field #%d - description', $field->get_id() ),
|
133 |
+
$field->get_description() );
|
134 |
+
}
|
135 |
+
|
136 |
+
// }}}
|
137 |
+
|
138 |
+
// {{{ Fees API integration.
|
139 |
+
|
140 |
+
function register_fees_strings() {
|
141 |
+
if ( isset( $_GET['action'] ) || ! function_exists( 'icl_register_string' ) )
|
142 |
+
return;
|
143 |
+
|
144 |
+
$fees = wpbdp_fees_api()->get_fees();
|
145 |
+
|
146 |
+
foreach ( $fees as &$f ) {
|
147 |
+
icl_register_string( 'Business Directory Plugin',
|
148 |
+
sprintf( 'Fee label (#%d)', $f->id ),
|
149 |
+
$f->label );
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
function translate_fee_label( $label, $fee ) {
|
154 |
+
if ( ! function_exists( 'icl_t' ) )
|
155 |
+
return $label;
|
156 |
+
|
157 |
+
return icl_t( 'Business Directory Plugin',
|
158 |
+
sprintf( 'Fee label (#%d)', $fee->id ),
|
159 |
+
$fee->label );
|
160 |
+
}
|
161 |
+
|
162 |
+
// }}}
|
163 |
+
}
|
core/compatibility/deprecated.php
ADDED
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Deprecated functionality.
|
4 |
+
*/
|
5 |
+
|
6 |
+
$wpbusdirmanconfigoptionsprefix = "wpbusdirman";
|
7 |
+
|
8 |
+
$wpbdmposttype = "wpbdp_listing";
|
9 |
+
$wpbdmposttypecategory = "wpbdp_category";
|
10 |
+
$wpbdmposttypetags = "wpbdp_tag";
|
11 |
+
|
12 |
+
define('WPBUSDIRMAN_TEMPLATES_PATH', WPBDP_PATH . '/core/compatibility/deprecated/templates');
|
13 |
+
|
14 |
+
|
15 |
+
/* template-related */
|
16 |
+
function wpbusdirman_single_listing_details() {
|
17 |
+
echo wpbusdirman_post_single_listing_details();
|
18 |
+
}
|
19 |
+
|
20 |
+
function wpbusdirman_post_single_listing_details() {
|
21 |
+
return wpbdp_render_listing( null, 'single' );
|
22 |
+
}
|
23 |
+
|
24 |
+
function wpbusdirman_the_listing_title() {
|
25 |
+
if ( $field = wpbdp_get_form_fields( array( 'association' => 'title', 'unique' => true ) ) )
|
26 |
+
return $field->display( get_the_ID() );
|
27 |
+
}
|
28 |
+
|
29 |
+
function wpbusdirman_the_listing_excerpt() {
|
30 |
+
if ( $field = wpbdp_get_form_fields( array( 'association' => 'excerpt', 'unique' => true ) ) )
|
31 |
+
return $field->display( get_the_ID() );
|
32 |
+
}
|
33 |
+
|
34 |
+
function wpbusdirman_the_listing_content() {
|
35 |
+
if ( $field = wpbdp_get_form_fields( array( 'association' => 'content', 'unique' => true ) ) )
|
36 |
+
return $field->display( get_the_ID() );
|
37 |
+
}
|
38 |
+
|
39 |
+
function wpbusdirman_the_listing_category() {
|
40 |
+
if ( $field = wpbdp_get_form_fields( array( 'association' => 'category', 'unique' => true ) ) )
|
41 |
+
return $field->display( get_the_ID() );
|
42 |
+
}
|
43 |
+
|
44 |
+
function wpbusdirman_the_listing_tags() {
|
45 |
+
if ( $field = wpbdp_get_form_fields( array( 'association' => 'tags', 'unique' => true ) ) )
|
46 |
+
return $field->display( get_the_ID() );
|
47 |
+
}
|
48 |
+
|
49 |
+
function wpbusdirman_the_listing_meta($excerptorsingle) {
|
50 |
+
$html = '';
|
51 |
+
$fields = wpbdp_get_form_fields( array( 'association' => 'meta' ) );
|
52 |
+
|
53 |
+
foreach ( $fields as &$f ) {
|
54 |
+
if ( $excerptorsingle == 'excerpt' && !$field->display_in( 'excerpt' ) )
|
55 |
+
continue;
|
56 |
+
|
57 |
+
$html .= $f->display( get_the_ID() );
|
58 |
+
}
|
59 |
+
|
60 |
+
return $html;
|
61 |
+
}
|
62 |
+
|
63 |
+
function wpbusdirman_display_excerpt($deprecated=null) {
|
64 |
+
echo wpbusdirman_post_excerpt($deprecated);
|
65 |
+
}
|
66 |
+
|
67 |
+
function wpbusdirman_post_excerpt($deprecated=null) {
|
68 |
+
return wpbdp_render_listing( null, 'excerpt' );
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @deprecated since 2.3
|
74 |
+
*/
|
75 |
+
function wpbusdirman_display_main_image() {
|
76 |
+
echo wpbusdirman_post_main_image();
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @deprecated since 2.3
|
81 |
+
*/
|
82 |
+
function wpbusdirman_post_main_image() {
|
83 |
+
return wpbdp_listing_thumbnail();
|
84 |
+
}
|
85 |
+
|
86 |
+
function wpbusdirman_display_extra_thumbnails() {
|
87 |
+
echo wpbusdirman_post_extra_thumbnails();
|
88 |
+
}
|
89 |
+
|
90 |
+
function wpbusdirman_post_extra_thumbnails() {
|
91 |
+
$html = '';
|
92 |
+
|
93 |
+
$thumbnail_id = wpbdp_listings_api()->get_thumbnail_id(get_the_ID());
|
94 |
+
$images = wpbdp_listings_api()->get_images(get_the_ID());
|
95 |
+
|
96 |
+
if ($images) {
|
97 |
+
$html .= '<div class="extrathumbnails">';
|
98 |
+
|
99 |
+
foreach ($images as $img) {
|
100 |
+
if ($img->ID == $thumbnail_id)
|
101 |
+
continue;
|
102 |
+
|
103 |
+
$html .= sprintf('<a class="thickbox" href="%s"><img class="wpbdmthumbs" src="%s" alt="%s" title="%s" border="0" /></a>',
|
104 |
+
wp_get_attachment_url($img->ID),
|
105 |
+
wp_get_attachment_thumb_url($img->ID),
|
106 |
+
the_title(null, null, false),
|
107 |
+
the_title(null, null, false)
|
108 |
+
);
|
109 |
+
}
|
110 |
+
|
111 |
+
$html .= '</div>';
|
112 |
+
}
|
113 |
+
|
114 |
+
return $html;
|
115 |
+
}
|
116 |
+
|
117 |
+
// Display the listing fields in excerpt view
|
118 |
+
function wpbusdirman_display_the_listing_fields() {
|
119 |
+
global $post;
|
120 |
+
|
121 |
+
$html = '';
|
122 |
+
|
123 |
+
foreach ( wpbdp_formfields_api()->get_fields() as $field ) {
|
124 |
+
if ( !$field->display_in( 'excerpt' ) )
|
125 |
+
continue;
|
126 |
+
|
127 |
+
$html .= $field->display( $post->ID, 'excerpt' );
|
128 |
+
}
|
129 |
+
|
130 |
+
return $html;
|
131 |
+
}
|
132 |
+
|
133 |
+
//Display the listing thumbnail
|
134 |
+
function wpbusdirman_display_the_thumbnail() {
|
135 |
+
return wpbdp_listing_thumbnail();
|
136 |
+
}
|
137 |
+
|
138 |
+
function wpbusdirman_sticky_loop() { return; }
|
139 |
+
|
140 |
+
function wpbusdirman_view_edit_delete_listing_button() {
|
141 |
+
$wpbusdirman_permalink=get_permalink(wpbdp_get_page_id('main'));
|
142 |
+
$html = '';
|
143 |
+
|
144 |
+
$html .= '<div style="clear:both;"></div><div class="vieweditbuttons"><div class="vieweditbutton"><form method="post" action="' . get_permalink() . '"><input type="hidden" name="action" value="viewlisting" /><input type="hidden" name="wpbusdirmanlistingid" value="' . get_the_id() . '" /><input type="submit" value="' . __("View","WPBDM") . '" class="button" /></form></div>';
|
145 |
+
|
146 |
+
if ( (wp_get_current_user()->ID == get_the_author_meta('ID')) || current_user_can('administrator')) {
|
147 |
+
$html .= '<div class="vieweditbutton"><form method="post" action="' . $wpbusdirman_permalink . '"><input type="hidden" name="action" value="editlisting" /><input type="hidden" name="listing_id" value="' . get_the_id() . '" /><input type="submit" value="' . __("Edit","WPBDM") . '" /></form></div><div class="vieweditbutton"><form method="post" action="' . $wpbusdirman_permalink . '"><input type="hidden" name="action" value="deletelisting" /><input type="hidden" name="listing_id" value="' . get_the_id() . '" /><input type="submit" value="' . __("Delete","WPBDM") . '" class="button" /></form></div>';
|
148 |
+
}
|
149 |
+
$html .= '</div>';
|
150 |
+
|
151 |
+
return $html;
|
152 |
+
}
|
153 |
+
|
154 |
+
function wpbusdirman_menu_button_upgradelisting() {
|
155 |
+
$post_id = get_the_ID();
|
156 |
+
|
157 |
+
if ( wpbdp_get_option('featured-on') &&
|
158 |
+
(get_post($post_id)->post_author == wp_get_current_user()->ID) &&
|
159 |
+
wpbdp_listings_api()->get_sticky_status(get_the_ID()) == 'normal' ) {
|
160 |
+
return '<form method="post" action="' . wpbdp_get_page_link('main') . '"><input type="hidden" name="action" value="upgradetostickylisting" /><input type="hidden" name="listing_id" value="' . $post_id . '" /><input type="submit" class="updradetostickylistingbutton" value="' . __("Upgrade Listing","WPBDM") . '" /></form>';
|
161 |
+
}
|
162 |
+
|
163 |
+
return '';
|
164 |
+
}
|
165 |
+
|
166 |
+
function wpbusdirman_latest_listings($numlistings) {
|
167 |
+
return wpbdp_latest_listings($numlistings);
|
168 |
+
}
|
169 |
+
|
170 |
+
function wpbusdirman_post_catpage_title() {
|
171 |
+
$categories = WPBDP_CATEGORY_TAX;
|
172 |
+
|
173 |
+
if ( get_query_var($categories) ) {
|
174 |
+
$term = get_term_by('slug', get_query_var($categories), $categories);
|
175 |
+
} else if ( get_query_var('taxonomy') == $categories ) {
|
176 |
+
$term = get_term_by('slug', get_query_var('term'), $categories);
|
177 |
+
} elseif ( get_query_var('taxonomy') == WPBDP_TAGS_TAX ) {
|
178 |
+
$term = get_term_by('slug', get_query_var('term'), WPBDP_TAGS_TAX);
|
179 |
+
}
|
180 |
+
|
181 |
+
return esc_attr($term->name);
|
182 |
+
}
|
183 |
+
|
184 |
+
function wpbusdirman_list_categories() {
|
185 |
+
echo wpbusdirman_post_list_categories();
|
186 |
+
}
|
187 |
+
|
188 |
+
function wpbusdirman_post_list_categories() {
|
189 |
+
return wpbdp_directory_categories();
|
190 |
+
}
|
191 |
+
|
192 |
+
function wpbusdirman_menu_buttons()
|
193 |
+
{
|
194 |
+
echo wpbusdirman_post_menu_buttons();
|
195 |
+
}
|
196 |
+
|
197 |
+
function wpbusdirman_post_menu_buttons()
|
198 |
+
{
|
199 |
+
$html = '';
|
200 |
+
$html .= '<div>' . wpbusdirman_post_menu_button_submitlisting() . wpbusdirman_menu_button_directory() . '</div><div style="clear: both;"></div>';
|
201 |
+
return $html;
|
202 |
+
}
|
203 |
+
|
204 |
+
function wpbusdirman_menu_button_submitlisting()
|
205 |
+
{
|
206 |
+
echo wpbusdirman_post_menu_button_submitlisting();
|
207 |
+
}
|
208 |
+
|
209 |
+
function wpbusdirman_post_menu_button_submitlisting()
|
210 |
+
{
|
211 |
+
if (!wpbdp_get_option('show-submit-listing'))
|
212 |
+
return '';
|
213 |
+
|
214 |
+
return '<form method="post" action="' . wpbdp_get_page_link('add-listing') . '"><input type="hidden" name="action" value="submitlisting" /><input type="submit" class="submitlistingbutton" value="' . __("Submit A Listing","WPBDM") . '" /></form>';
|
215 |
+
}
|
216 |
+
|
217 |
+
function wpbusdirman_menu_button_viewlistings()
|
218 |
+
{
|
219 |
+
echo wpbusdirman_post_menu_button_viewlistings();
|
220 |
+
}
|
221 |
+
|
222 |
+
function wpbusdirman_post_menu_button_viewlistings()
|
223 |
+
{
|
224 |
+
if (!wpbdp_get_option('show-view-listings'))
|
225 |
+
return '';
|
226 |
+
|
227 |
+
return '<form method="post" action="' . wpbdp_get_page_link('view-listings') . '"><input type="hidden" name="action" value="viewlistings" /><input type="submit" class="viewlistingsbutton" value="' . __("View Listings","WPBDM") . '" /></form>';
|
228 |
+
}
|
229 |
+
|
230 |
+
function wpbusdirman_menu_button_directory()
|
231 |
+
{
|
232 |
+
|
233 |
+
echo wpbusdirman_post_menu_button_directory();
|
234 |
+
}
|
235 |
+
|
236 |
+
function wpbusdirman_post_menu_button_directory()
|
237 |
+
{
|
238 |
+
return '<form method="post" action="' . wpbdp_get_page_link('main') . '"><input type="submit" class="viewlistingsbutton" value="' . __("Directory","WPBDM") . '" /></form>';
|
239 |
+
}
|
240 |
+
|
241 |
+
function wpbusdirman_menu_button_editlisting()
|
242 |
+
{
|
243 |
+
global $post;
|
244 |
+
$wpbusdirman_permalink=get_permalink(wpbdp_get_page_id('main'));
|
245 |
+
$html = '';
|
246 |
+
|
247 |
+
if(is_user_logged_in())
|
248 |
+
{
|
249 |
+
global $current_user;
|
250 |
+
get_currentuserinfo();
|
251 |
+
$wpbusdirmanloggedinuseremail=$current_user->user_email;
|
252 |
+
$wpbusdirmanauthoremail=get_the_author_meta('user_email');
|
253 |
+
if($wpbusdirmanloggedinuseremail == $wpbusdirmanauthoremail || current_user_can('administrator') || (wp_get_current_user()->ID == get_the_author_meta('ID')))
|
254 |
+
{
|
255 |
+
$html .= '<form method="post" action="' . $wpbusdirman_permalink . '"><input type="hidden" name="action" value="editlisting" /><input type="hidden" name="listing_id" value="' . $post->ID . '" /><input type="submit" class="editlistingbutton" value="' . __("Edit Listing","WPBDM") . '" /></form>';
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
return $html;
|
260 |
+
}
|
261 |
+
|
262 |
+
/* deprecated since 2.1.4 */
|
263 |
+
function wpbdp_sticky_loop($category_id=null, $taxonomy=null) { return ''; }
|
264 |
+
|
265 |
+
/* deprecated since 2.1.6 */
|
266 |
+
function wpbusdirman_dropdown_categories() {
|
267 |
+
$html = '';
|
268 |
+
|
269 |
+
$html .= sprintf('<form action="%s">', site_url('/'));
|
270 |
+
$html .= wp_dropdown_categories(array(
|
271 |
+
'taxonomy' => WPBDP_CATEGORY_TAX,
|
272 |
+
'show_option_none' => '—',
|
273 |
+
'order' => wpbdp_get_option('categories-sort'),
|
274 |
+
'orderby' => wpbdp_get_option('categories-order-by'),
|
275 |
+
'hide_empty' => wpbdp_get_option('hide-empty-categories'),
|
276 |
+
'hierarchical' => !wpbdp_get_option('show-only-parent-categories'),
|
277 |
+
'echo' => false,
|
278 |
+
'name' => WPBDP_CATEGORY_TAX
|
279 |
+
));
|
280 |
+
|
281 |
+
$html = preg_replace("/\\<select(.*)name=('|\")(.*)('|\")(.*)\\>/uiUs",
|
282 |
+
"<select name=\"$3\" onchange=\"return this.form.submit();\" $1 $5>",
|
283 |
+
$html);
|
284 |
+
|
285 |
+
// no-script support
|
286 |
+
$html .= '<noscript>';
|
287 |
+
$html .= '<input type="submit" value="→" />';
|
288 |
+
$html .= '</noscript>';
|
289 |
+
$html .= '</form>';
|
290 |
+
|
291 |
+
return $html;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Small compatibility layer with old forms API. To be removed in later releases.
|
296 |
+
* @deprecated
|
297 |
+
* @since 2.3
|
298 |
+
*/
|
299 |
+
function wpbdp_get_formfields() {
|
300 |
+
global $wpbdp;
|
301 |
+
$res = array();
|
302 |
+
|
303 |
+
foreach ( $wpbdp->formfields->get_fields() as $new_field ) {
|
304 |
+
$field = new StdClass();
|
305 |
+
$field->id = $new_field->get_id();
|
306 |
+
$field->label = $new_field->get_label();
|
307 |
+
$field->association = $new_field->get_association();
|
308 |
+
$field->type = $new_field->get_field_type()->get_id();
|
309 |
+
|
310 |
+
$res[] = $field;
|
311 |
+
}
|
312 |
+
|
313 |
+
return $res;
|
314 |
+
}
|
315 |
+
|
316 |
+
|
317 |
+
/**
|
318 |
+
* @deprecated
|
319 |
+
* @since 2.3
|
320 |
+
*/
|
321 |
+
function wpbusdirman_get_the_business_email($post_id) {
|
322 |
+
$email_mode = wpbdp_get_option( 'listing-email-mode' );
|
323 |
+
|
324 |
+
$email_field_value = '';
|
325 |
+
if ( $email_field = wpbdp_get_form_fields( 'validators=email&unique=1' ) ) {
|
326 |
+
$email_field_value = trim( $email_field->plain_value( $post_id ) );
|
327 |
+
}
|
328 |
+
|
329 |
+
if ( $email_mode == 'field' && !empty( $email_field_value ) )
|
330 |
+
return $email_field_value;
|
331 |
+
|
332 |
+
$author_email = '';
|
333 |
+
$post = get_post( $post_id );
|
334 |
+
$author_email = trim( get_the_author_meta( 'user_email', $post->post_author ) );
|
335 |
+
|
336 |
+
if ( empty( $author_email ) && !empty( $email_field_value ) )
|
337 |
+
return $email_field_value;
|
338 |
+
|
339 |
+
return $author_email ? $author_email : '';
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* @deprecated since 2.3
|
344 |
+
*/
|
345 |
+
function wpbdp_post_type() {
|
346 |
+
return WPBDP_POST_TYPE;
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* @deprecated since 2.3
|
351 |
+
*/
|
352 |
+
function wpbdp_categories_taxonomy() {
|
353 |
+
return WPBDP_CATEGORY_TAX;
|
354 |
+
}
|
core/compatibility/templates/businessdirectory-category.tpl.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// THIS TEMPLATE IS DEPRECATED. DO NOT USE.
|
3 |
+
// See http://businessdirectoryplugin.com/docs/matching-the-design-to-your-theme/ for info on Business Directory templates.
|
4 |
+
?>
|
5 |
+
<?php get_header(); ?>
|
6 |
+
<div id="content">
|
7 |
+
|
8 |
+
<div id="wpbdp-category-page" class="wpbdp-category-page businessdirectory-category businessdirectory wpbdp-page">
|
9 |
+
<div class="wpbdp-bar cf">
|
10 |
+
<?php wpbdp_the_main_links(); ?>
|
11 |
+
<?php wpbdp_the_search_form(); ?>
|
12 |
+
</div>
|
13 |
+
|
14 |
+
<h2 class="category-name"><?php echo wpbusdirman_post_catpage_title(); ?></h2>
|
15 |
+
<?php echo wpbdp_render('businessdirectory-listings'); ?>
|
16 |
+
</div>
|
17 |
+
|
18 |
+
</div>
|
19 |
+
<?php get_footer(); ?>
|
core/compatibility/templates/businessdirectory-single.tpl.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php get_header(); ?>
|
2 |
+
|
3 |
+
<?php the_post(); ?>
|
4 |
+
|
5 |
+
<div id="content">
|
6 |
+
<?php // Customize the output of this function using the template "businessdirectory-listing.tpl.php"; ?>
|
7 |
+
<?php echo wpbdp_render_listing(null, 'single'); ?>
|
8 |
+
</div>
|
9 |
+
|
10 |
+
<?php get_footer(); ?>
|
core/compatibility/templates/wpbusdirman-index-categories.php
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="wpbdmentry">
|
2 |
+
<div id="lco">
|
3 |
+
<div class="left buttonform">
|
4 |
+
<?php echo wpbusdirman_post_menu_button_submitlisting() ;?>
|
5 |
+
<?php echo wpbusdirman_post_menu_button_viewlistings() ;?>
|
6 |
+
</div>
|
7 |
+
|
8 |
+
<div class="right">
|
9 |
+
<form id="wpbdmsearchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
|
10 |
+
<input id="intextbox" maxlength="150" name="s" size="20" type="text" value="" />
|
11 |
+
<input name="post_type" type="hidden" value="<?php echo wpbdp()->get_post_type(); ?>" />
|
12 |
+
<input id="wpbdmsearchsubmit" class="wpbdmsearchbutton" type="submit" value="<?php _ex('Search Listings', 'templates', 'WPBDM'); ?>" />
|
13 |
+
</form>
|
14 |
+
</div>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<div id="wpbusdirmancats">
|
18 |
+
<div style="clear:both;"></div>
|
19 |
+
<ul><?php print wpbusdirman_post_list_categories(); ?></ul>
|
20 |
+
</div>
|
21 |
+
<br style="clear: both;" />
|
22 |
+
</div>
|
core/css/debug.css
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
#wpbdp-debugging {
|
3 |
+
font-family: Menlo, Consolas, monospace;
|
4 |
+
color: #000;
|
5 |
+
width: 100%;
|
6 |
+
margin: 2px 0;
|
7 |
+
clear:both;
|
8 |
+
font-size: 11px;
|
9 |
+
max-height: 150px;
|
10 |
+
overflow-y: scroll;
|
11 |
+
}
|
12 |
+
|
13 |
+
#wpbdp-debugging .tab {
|
14 |
+
padding: 5px 0 0 0;
|
15 |
+
display: none;
|
16 |
+
}
|
17 |
+
|
18 |
+
#wpbdp-debugging table { width: 100%; border-collapse: collapse; }
|
19 |
+
|
20 |
+
#wpbdp-debugging table tr { cursor: pointer; }
|
21 |
+
#wpbdp-debugging table td { padding: 0; }
|
22 |
+
#wpbdp-debugging table td.handle { vertical-align: top; width: 10px; }
|
23 |
+
#wpbdp-debugging table td.timestamp { width: 50px; }
|
24 |
+
#wpbdp-debugging table td.type { width: 100px; }
|
25 |
+
#wpbdp-debugging table td.message { max-width: 450px; }
|
26 |
+
#wpbdp-debugging table td.context { width: 200px; }
|
27 |
+
#wpbdp-debugging table td.file { width: 200px; }
|
28 |
+
|
29 |
+
#wpbdp-debugging table td .extradata {
|
30 |
+
margin: 0;
|
31 |
+
border-left: solid 5px #666;
|
32 |
+
padding: 0 0 0 20px;
|
33 |
+
font-size: 90%;
|
34 |
+
color: #666;
|
35 |
+
display: none;
|
36 |
+
}
|
37 |
+
|
38 |
+
#wpbdp-debugging table td .extradata dl {
|
39 |
+
padding: 0;
|
40 |
+
margin: 0;
|
41 |
+
}
|
42 |
+
|
43 |
+
#wpbdp-debugging table td .extradata dt {
|
44 |
+
font-weight: bold;
|
45 |
+
}
|
46 |
+
|
47 |
+
#wpbdp-debugging .php-warning { background: #FFFAA5; }
|
48 |
+
#wpbdp-debugging .php-notice { background: #FFFAA5; }
|
49 |
+
#wpbdp-debugging .php-deprecated { background: #efefef; }
|
50 |
+
|
51 |
+
#wpbdp-debugging .tab-selector {
|
52 |
+
padding: 0;
|
53 |
+
margin: 0;
|
54 |
+
border-bottom: solid 1px #666;
|
55 |
+
}
|
56 |
+
|
57 |
+
#wpbdp-debugging .tab-selector li {
|
58 |
+
display: inline-block;
|
59 |
+
margin: 0;
|
60 |
+
margin-right: 10px;
|
61 |
+
padding: 0 5px;
|
62 |
+
background: #666;
|
63 |
+
}
|
64 |
+
|
65 |
+
#wpbdp-debugging .tab-selector li.active {
|
66 |
+
background: #000;
|
67 |
+
}
|
68 |
+
|
69 |
+
#wpbdp-debugging .tab-selector li.active a {
|
70 |
+
color: #fff;
|
71 |
+
}
|
72 |
+
|
73 |
+
#wpbdp-debugging .tab-selector li a {
|
74 |
+
text-decoration: none;
|
75 |
+
color: #efefef;
|
76 |
+
}
|
core/css/debug.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#wpbdp-debugging{font-family:Menlo,Consolas,monospace;color:#000;width:100%;margin:2px 0;clear:both;font-size:11px;max-height:150px;overflow-y:scroll}#wpbdp-debugging .tab{padding:5px 0 0 0;display:none}#wpbdp-debugging table{width:100%;border-collapse:collapse}#wpbdp-debugging table tr{cursor:pointer}#wpbdp-debugging table td{padding:0}#wpbdp-debugging table td.handle{vertical-align:top;width:10px}#wpbdp-debugging table td.timestamp{width:50px}#wpbdp-debugging table td.type{width:100px}#wpbdp-debugging table td.message{max-width:450px}#wpbdp-debugging table td.context{width:200px}#wpbdp-debugging table td.file{width:200px}#wpbdp-debugging table td .extradata{margin:0;border-left:solid 5px #666;padding:0 0 0 20px;font-size:90%;color:#666;display:none}#wpbdp-debugging table td .extradata dl{padding:0;margin:0}#wpbdp-debugging table td .extradata dt{font-weight:bold}#wpbdp-debugging .php-warning{background:#fffaa5}#wpbdp-debugging .php-notice{background:#fffaa5}#wpbdp-debugging .php-deprecated{background:#efefef}#wpbdp-debugging .tab-selector{padding:0;margin:0;border-bottom:solid 1px #666}#wpbdp-debugging .tab-selector li{display:inline-block;margin:0;margin-right:10px;padding:0 5px;background:#666}#wpbdp-debugging .tab-selector li.active{background:#000}#wpbdp-debugging .tab-selector li.active a{color:#fff}#wpbdp-debugging .tab-selector li a{text-decoration:none;color:#efefef}
|
core/css/dnd-upload.css
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.wpbdp-dnd-area {
|
2 |
+
margin: 0 auto;
|
3 |
+
border: 2px dashed #ddd;
|
4 |
+
width: 98%;
|
5 |
+
height: 180px;
|
6 |
+
color: #666;
|
7 |
+
}
|
8 |
+
|
9 |
+
.wpbdp-dnd-area .upload-button {
|
10 |
+
background: #fff;
|
11 |
+
position: relative;
|
12 |
+
overflow: hidden;
|
13 |
+
}
|
14 |
+
|
15 |
+
.wpbdp-dnd-area .upload-button a {
|
16 |
+
}
|
17 |
+
|
18 |
+
.wpbdp-dnd-area .upload-button input {
|
19 |
+
margin: 0;
|
20 |
+
padding: 0;
|
21 |
+
position: absolute;
|
22 |
+
top: 0;
|
23 |
+
left: 0;
|
24 |
+
right: 0;
|
25 |
+
bottom: 0;
|
26 |
+
width: 100%;
|
27 |
+
height: 100%;
|
28 |
+
opacity: 0;
|
29 |
+
cursor: pointer;
|
30 |
+
border: none;
|
31 |
+
}
|
32 |
+
|
33 |
+
.wpbdp-dnd-area.dragging {
|
34 |
+
background: #efefef;
|
35 |
+
}
|
36 |
+
|
37 |
+
.wpbdp-dnd-area .dnd-area-inside {
|
38 |
+
margin: 30px auto 0;
|
39 |
+
text-align: center;
|
40 |
+
color: #aaa;
|
41 |
+
}
|
42 |
+
|
43 |
+
.wpbdp-dnd-area .dnd-area-inside-working {
|
44 |
+
color: #000;
|
45 |
+
text-align: center;
|
46 |
+
margin: 50px auto 0;
|
47 |
+
}
|
48 |
+
|
49 |
+
.wpbdp-dnd-area .dnd-area-inside-working span {
|
50 |
+
font-weight: bold;
|
51 |
+
}
|
52 |
+
|
53 |
+
.wpbdp-dnd-area .dnd-area-inside-error {
|
54 |
+
font-size: 95%;
|
55 |
+
color: #900000;
|
56 |
+
text-align: center;
|
57 |
+
margin: 50px 25px;
|
58 |
+
}
|
59 |
+
|
core/css/dnd-upload.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.wpbdp-dnd-area{margin:0 auto;border:2px dashed #ddd;width:98%;height:180px;color:#666}.wpbdp-dnd-area .upload-button{background:#fff;position:relative;overflow:hidden}.wpbdp-dnd-area .upload-button input{margin:0;padding:0;position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;opacity:0;cursor:pointer;border:0}.wpbdp-dnd-area.dragging{background:#efefef}.wpbdp-dnd-area .dnd-area-inside{margin:30px auto 0;text-align:center;color:#aaa}.wpbdp-dnd-area .dnd-area-inside-working{color:#000;text-align:center;margin:50px auto 0}.wpbdp-dnd-area .dnd-area-inside-working span{font-weight:bold}.wpbdp-dnd-area .dnd-area-inside-error{font-size:95%;color:#900000;text-align:center;margin:50px 25px}
|
core/css/widgets.css
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ul.wpbdp-listings-widget-list {
|
2 |
+
}
|
3 |
+
|
4 |
+
ul.wpbdp-listings-widget-list li {
|
5 |
+
list-style: none;
|
6 |
+
border-bottom: 1px dotted #eee;
|
7 |
+
margin: 0;
|
8 |
+
padding: 2px 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
ul.wpbdp-listings-widget-list li .listing-title {
|
12 |
+
font-weight: bold;
|
13 |
+
display: block;
|
14 |
+
}
|
15 |
+
|
16 |
+
ul.wpbdp-listings-widget-list li .listing-image {
|
17 |
+
}
|
core/css/widgets.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
ul.wpbdp-listings-widget-list li{list-style:none;border-bottom:1px dotted #eee;margin:0;padding:2px 0}ul.wpbdp-listings-widget-list li .listing-title{font-weight:bold;display:block}
|
core/css/wpbdp-legacy.css
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.clear { clear:both;}
|
2 |
+
|
3 |
+
.wpbdmthumbs { padding:4px; -moz-box-shadow: 0 5px 5px #dddddd;
|
4 |
+
-webkit-box-shadow: 0 5px 5px #dddddd;margin-right:5px;
|
5 |
+
}
|
6 |
+
|
7 |
+
#wpbdmentry .viewlistingsbutton,
|
8 |
+
#wpbdmentry .submitlistingbutton,
|
9 |
+
#wpbdmentry .editlistingbutton,
|
10 |
+
#wpbdmentry .deletelistingbutton,
|
11 |
+
#wpbdmentry .exitnowbutton,
|
12 |
+
#wpbdmentry .insubmitbutton,
|
13 |
+
#wpbdmlistings .vieweditbutton input,
|
14 |
+
.vieweditbutton a, .vieweditbutton input,
|
15 |
+
.viewlistingsbutton,
|
16 |
+
.submitlistingbutton,
|
17 |
+
.editlistingbutton,
|
18 |
+
.deletelistingbutton,
|
19 |
+
.exitnowbutton,
|
20 |
+
.insubmitbutton {
|
21 |
+
background:#000000;
|
22 |
+
border:1px solid #000000;
|
23 |
+
-moz-border-radius: 4px;
|
24 |
+
-khtml-border-radius: 4px;
|
25 |
+
-webkit-border-radius: 4px;
|
26 |
+
border-radius: 4px;
|
27 |
+
width:auto;
|
28 |
+
color:#ffffff;
|
29 |
+
float:left;
|
30 |
+
text-align:center;
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
#editlistingsingleview { margin-bottom:15px;}
|
35 |
+
|
36 |
+
#editlistingsingleview .editlistingbutton
|
37 |
+
{
|
38 |
+
float:left;
|
39 |
+
margin-right:20px;
|
40 |
+
}
|
41 |
+
|
42 |
+
.singledetailsview { margin-top:15px;}
|
43 |
+
|
44 |
+
.deletelistingbutton {float:none;}
|
45 |
+
|
46 |
+
.exitnowbutton {float:none;}
|
47 |
+
|
48 |
+
.updradetostickylistingbutton {
|
49 |
+
background:#FFF0CF;
|
50 |
+
border:1px solid #B37800;
|
51 |
+
-moz-border-radius: 4px;
|
52 |
+
-khtml-border-radius: 4px;
|
53 |
+
-webkit-border-radius: 4px;
|
54 |
+
border-radius: 4px;
|
55 |
+
width:auto;
|
56 |
+
color:#B37800;
|
57 |
+
float:left;
|
58 |
+
text-align:center;
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
.intextbox { border:1px solid #dddddd; padding:3px; }
|
64 |
+
.inselect { border:1px solid #dddddd; padding:3px; }
|
65 |
+
.inselectmulitple { border:1px solid #dddddd; padding:3px; width:auto; height:auto; }
|
66 |
+
|
67 |
+
.intextarea { width:400px;border:1px solid #dddddd; height:200px; }
|
68 |
+
|
69 |
+
.insubmitbutton {}
|
70 |
+
|
71 |
+
#wpbusdirmancats { margin-bottom:20px; padding:10px;}
|
72 |
+
#wpbusdirmancats ul { margin-bottom:10px;margin-left:5px; }
|
73 |
+
#wpbusdirmancats ul li { float:left; width:200px; padding:5px; }
|
74 |
+
|
75 |
+
ul#wpbusdirmanerrors { margin-left:20px; }
|
76 |
+
ul#wpbusdirmanpaymentoptionslist { margin-left:20px; }
|
77 |
+
#wpbusdirmanpaymentoptionslist li { margin-left:20px; list-style-type:none;margin:3px 0px; }
|
78 |
+
|
79 |
+
#wpbdmlistings { list-style:none;width:100%; }
|
80 |
+
|
81 |
+
.wpbdmodd {background:#eeeeee;border-bottom:1px dotted #dddddd;}
|
82 |
+
.wpbdmeven {border:0;border-bottom:1px dotted #dddddd;}
|
83 |
+
.wpbdmoddsticky {background:#FFF0CF;border-bottom:1px solid #B37800;}
|
84 |
+
.wpbdmevensticky {background:#FFF0CF;border:0;border-bottom:1px solid #B37800;}
|
85 |
+
|
86 |
+
#wpbdmlistings .listingthumbnail {float:left;width:150px;margin:10px 0 0 10px;}
|
87 |
+
#wpbdmlistings .listingdetails { float:left;margin-left:20px;margin-top:10px;}
|
88 |
+
.wpbdmsingleimages { float:left;margin-right:10px; margin-bottom:10px;}
|
89 |
+
.wpbdmsingleimages img { max-width:375px;height:auto; -moz-box-shadow: 0 5px 5px #dddddd;
|
90 |
+
-webkit-box-shadow: 0 5px 5px #dddddd;}
|
91 |
+
.wpbdmsingledetails { float:left;margin-left:10px;width:50%;padding:10px;}
|
92 |
+
|
93 |
+
.paymentheader { background:#f2f2f2; padding:5px; color:#666666;}
|
94 |
+
.paymentbuttondiv {padding:10px; margin-bottom:10px;}
|
95 |
+
|
96 |
+
.wpbdmac { font-size:9px; text-align:center;}
|
97 |
+
|
98 |
+
.featuredlisting { width: 126px;
|
99 |
+
float:right; }
|
100 |
+
|
101 |
+
#wpbusdirmancontent { clear:both; padding:10px; background:#ffffff;}
|
102 |
+
|
103 |
+
select { margin-bottom:15px; }
|
104 |
+
textarea { margin-bottom:15px; }
|
105 |
+
#wpbdmentry p.wpbdmp { margin:0;padding:0;}
|
106 |
+
|
107 |
+
#wpbdmentry { width:100%;margin:0 auto;}
|
108 |
+
#wpbdmentry label { margin:0;padding:0; }
|
109 |
+
.extrathumbnails { max-width:375px;margin:10px auto 0 auto;}
|
110 |
+
|
111 |
+
#wpbdmcheckboxclass {float:left;margin-right:30px;width:40%;padding:10px 0;}
|
112 |
+
|
113 |
+
.vieweditbuttons {float:right;padding:10px;width:100%;}
|
114 |
+
.vieweditbutton {float:left;margin-left:10px;}
|
115 |
+
|
116 |
+
#wpbdmlistings .vieweditbutton input,
|
117 |
+
.vieweditbutton a, .vieweditbutton input {width:100%;}
|
118 |
+
|
119 |
+
.vieweditbutton a { text-decoration:none;}
|
120 |
+
|
121 |
+
|
122 |
+
.vieweditbutton input { margin-top:-15px;}
|
123 |
+
|
124 |
+
.feecategoriesheader { background:#dddddd;color:#333333;padding:10px;margin-bottom:5px;}
|
125 |
+
|
126 |
+
.menubuttons { }
|
127 |
+
#lhbuttons { float:right;width:150px;}
|
128 |
+
#lhbuttons .viewlistingsbutton { margin-right:10px;}
|
129 |
+
.ldetails { padding:10px; background:#eeeeee;}
|
130 |
+
#lco { width:100%; -moz-box-shadow: 0 5px 5px #dddddd;
|
131 |
+
-webkit-box-shadow: 0 5px 5px #dddddd;background:#f7f7f7; margin:10px 0;}
|
132 |
+
#lco .title { width:50%;float:left;padding:10px;font-weight:bold;font-size:22px;margin-top:5px;}
|
133 |
+
#lco .title h1 { border:0;margin:0;}
|
134 |
+
#lco .buttonform { float:left;width:40%;padding:10px;}
|
135 |
+
#lco .buttonform input { }
|
136 |
+
#lco .title input { }
|
137 |
+
#lco .title .submitlistingbutton { margin-right:10px; }
|
138 |
+
#lco .buttonform .viewlistingsbutton { margin-right:10px;}
|
139 |
+
#lco .buttonform .submitlistingbutton { margin-right:10px;}
|
140 |
+
|
141 |
+
#wpbdmentry .fixpadding { width:98%;}
|
142 |
+
|
143 |
+
#lco #wpbdmsearchform #intextbox { color:#000000; }
|
144 |
+
#lco #wpbdmsearchform #wpbdmsearchsubmit {
|
145 |
+
background:#000000;
|
146 |
+
border:1px solid #000000;
|
147 |
+
-moz-border-radius: 4px;
|
148 |
+
-khtml-border-radius: 4px;
|
149 |
+
-webkit-border-radius: 4px;
|
150 |
+
border-radius: 4px;
|
151 |
+
width:auto;
|
152 |
+
color:#ffffff;
|
153 |
+
text-align:center;
|
154 |
+
display: block;
|
155 |
+
}
|
156 |
+
|
157 |
+
#lco {
|
158 |
+
min-height: 80px;
|
159 |
+
}
|
160 |
+
|
161 |
+
#lco .left {
|
162 |
+
float: left;
|
163 |
+
padding: 10px;
|
164 |
+
}
|
165 |
+
|
166 |
+
#lco .left input[type="submit"] {
|
167 |
+
margin-top: 2px;
|
168 |
+
width: 100%;
|
169 |
+
}
|
170 |
+
|
171 |
+
#lco .right {
|
172 |
+
padding: 10px;
|
173 |
+
margin-left: 200px;
|
174 |
+
width: 200px;
|
175 |
+
}
|
176 |
+
|
177 |
+
#lco .right #intextbox {
|
178 |
+
width: 100%;
|
179 |
+
}
|
180 |
+
|
181 |
+
#lco .right #wpbdmsearchsubmit {
|
182 |
+
margin: auto;
|
183 |
+
}
|
184 |
+
|
185 |
+
#lco input[type="submit"] {
|
186 |
+
cursor: pointer;
|
187 |
+
}
|
core/css/wpbdp-legacy.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.clear{clear:both}.wpbdmthumbs{padding:4px;-moz-box-shadow:0 5px 5px #ddd;-webkit-box-shadow:0 5px 5px #ddd;margin-right:5px}#wpbdmentry .viewlistingsbutton,#wpbdmentry .submitlistingbutton,#wpbdmentry .editlistingbutton,#wpbdmentry .deletelistingbutton,#wpbdmentry .exitnowbutton,#wpbdmentry .insubmitbutton,#wpbdmlistings .vieweditbutton input,.vieweditbutton a,.vieweditbutton input,.viewlistingsbutton,.submitlistingbutton,.editlistingbutton,.deletelistingbutton,.exitnowbutton,.insubmitbutton{background:#000;border:1px solid #000;-moz-border-radius:4px;-khtml-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;width:auto;color:#fff;float:left;text-align:center}#editlistingsingleview{margin-bottom:15px}#editlistingsingleview .editlistingbutton{float:left;margin-right:20px}.singledetailsview{margin-top:15px}.deletelistingbutton{float:none}.exitnowbutton{float:none}.updradetostickylistingbutton{background:#fff0cf;border:1px solid #b37800;-moz-border-radius:4px;-khtml-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;width:auto;color:#b37800;float:left;text-align:center}.intextbox{border:1px solid #ddd;padding:3px}.inselect{border:1px solid #ddd;padding:3px}.inselectmulitple{border:1px solid #ddd;padding:3px;width:auto;height:auto}.intextarea{width:400px;border:1px solid #ddd;height:200px}#wpbusdirmancats{margin-bottom:20px;padding:10px}#wpbusdirmancats ul{margin-bottom:10px;margin-left:5px}#wpbusdirmancats ul li{float:left;width:200px;padding:5px}ul#wpbusdirmanerrors{margin-left:20px}ul#wpbusdirmanpaymentoptionslist{margin-left:20px}#wpbusdirmanpaymentoptionslist li{margin-left:20px;list-style-type:none;margin:3px 0}#wpbdmlistings{list-style:none;width:100%}.wpbdmodd{background:#eee;border-bottom:1px dotted #ddd}.wpbdmeven{border:0;border-bottom:1px dotted #ddd}.wpbdmoddsticky{background:#fff0cf;border-bottom:1px solid #b37800}.wpbdmevensticky{background:#fff0cf;border:0;border-bottom:1px solid #b37800}#wpbdmlistings .listingthumbnail{float:left;width:150px;margin:10px 0 0 10px}#wpbdmlistings .listingdetails{float:left;margin-left:20px;margin-top:10px}.wpbdmsingleimages{float:left;margin-right:10px;margin-bottom:10px}.wpbdmsingleimages img{max-width:375px;height:auto;-moz-box-shadow:0 5px 5px #ddd;-webkit-box-shadow:0 5px 5px #ddd}.wpbdmsingledetails{float:left;margin-left:10px;width:50%;padding:10px}.paymentheader{background:#f2f2f2;padding:5px;color:#666}.paymentbuttondiv{padding:10px;margin-bottom:10px}.wpbdmac{font-size:9px;text-align:center}.featuredlisting{width:126px;float:right}#wpbusdirmancontent{clear:both;padding:10px;background:#fff}select{margin-bottom:15px}textarea{margin-bottom:15px}#wpbdmentry p.wpbdmp{margin:0;padding:0}#wpbdmentry{width:100%;margin:0 auto}#wpbdmentry label{margin:0;padding:0}.extrathumbnails{max-width:375px;margin:10px auto 0 auto}#wpbdmcheckboxclass{float:left;margin-right:30px;width:40%;padding:10px 0}.vieweditbuttons{float:right;padding:10px;width:100%}.vieweditbutton{float:left;margin-left:10px}#wpbdmlistings .vieweditbutton input,.vieweditbutton a,.vieweditbutton input{width:100%}.vieweditbutton a{text-decoration:none}.vieweditbutton input{margin-top:-15px}.feecategoriesheader{background:#ddd;color:#333;padding:10px;margin-bottom:5px}#lhbuttons{float:right;width:150px}#lhbuttons .viewlistingsbutton{margin-right:10px}.ldetails{padding:10px;background:#eee}#lco{width:100%;-moz-box-shadow:0 5px 5px #ddd;-webkit-box-shadow:0 5px 5px #ddd;background:#f7f7f7;margin:10px 0}#lco .title{width:50%;float:left;padding:10px;font-weight:bold;font-size:22px;margin-top:5px}#lco .title h1{border:0;margin:0}#lco .buttonform{float:left;width:40%;padding:10px}#lco .title .submitlistingbutton{margin-right:10px}#lco .buttonform .viewlistingsbutton{margin-right:10px}#lco .buttonform .submitlistingbutton{margin-right:10px}#wpbdmentry .fixpadding{width:98%}#lco #wpbdmsearchform #intextbox{color:#000}#lco #wpbdmsearchform #wpbdmsearchsubmit{background:#000;border:1px solid #000;-moz-border-radius:4px;-khtml-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;width:auto;color:#fff;text-align:center;display:block}#lco{min-height:80px}#lco .left{float:left;padding:10px}#lco .left input[type="submit"]{margin-top:2px;width:100%}#lco .right{padding:10px;margin-left:200px;width:200px}#lco .right #intextbox{width:100%}#lco .right #wpbdmsearchsubmit{margin:auto}#lco input[type="submit"]{cursor:pointer}
|
core/css/wpbdp.css
ADDED
@@ -0,0 +1,559 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Search Form
|
3 |
+
*/
|
4 |
+
form#wpbdmsearchform {
|
5 |
+
padding: 12px 0;
|
6 |
+
text-align: center;
|
7 |
+
}
|
8 |
+
|
9 |
+
form#wpbdmsearchform input {
|
10 |
+
display: inline;
|
11 |
+
}
|
12 |
+
|
13 |
+
form#wpbdmsearchform .wpbdmsearchbutton {
|
14 |
+
margin-top: 5px;
|
15 |
+
}
|
16 |
+
|
17 |
+
form#wpbdmsearchform a.advanced-search-link {
|
18 |
+
font-size: 70%;
|
19 |
+
display: block;
|
20 |
+
}
|
21 |
+
|
22 |
+
#wpbdp-search-form {
|
23 |
+
padding-left: 10px;
|
24 |
+
}
|
25 |
+
|
26 |
+
#wpbdp-search-form .wpbdp-search-filter {
|
27 |
+
margin-bottom: 10px;
|
28 |
+
clear: both;
|
29 |
+
}
|
30 |
+
|
31 |
+
#wpbdp-search-form .wpbdp-search-filter > div.label {
|
32 |
+
display: block;
|
33 |
+
width: 40%;
|
34 |
+
float: left;
|
35 |
+
}
|
36 |
+
|
37 |
+
#wpbdp-search-form .wpbdp-search-filter > div.field {
|
38 |
+
display: block;
|
39 |
+
width: 60%;
|
40 |
+
margin-left: 40%;
|
41 |
+
padding-left: 5px;
|
42 |
+
}
|
43 |
+
|
44 |
+
#wpbdp-search-form .wpbdp-search-filter > div.field > input[type="text"] {
|
45 |
+
width: 90%;
|
46 |
+
}
|
47 |
+
|
48 |
+
#wpbdp-search-form .wpbdp-search-filter > div.field > select {
|
49 |
+
width: 90%;
|
50 |
+
}
|
51 |
+
|
52 |
+
#wpbdp-search-form input[type="submit"] {
|
53 |
+
width: 100px;
|
54 |
+
float: none;
|
55 |
+
margin: auto;
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
.cf:before, .cf:after {
|
60 |
+
content: " "; /* 1 */
|
61 |
+
display: table; /* 2 */
|
62 |
+
}
|
63 |
+
|
64 |
+
.cf:after { clear: both; }
|
65 |
+
.cf { *zoom: 1; }
|
66 |
+
|
67 |
+
.wpbdp-pagination {
|
68 |
+
margin: 25px 0 0 0;
|
69 |
+
}
|
70 |
+
|
71 |
+
.wpbdp-pagination .next {
|
72 |
+
float: right;
|
73 |
+
}
|
74 |
+
|
75 |
+
/* listing views */
|
76 |
+
.listing-actions form {
|
77 |
+
margin: 0;
|
78 |
+
padding: 0;
|
79 |
+
display: inline;
|
80 |
+
}
|
81 |
+
|
82 |
+
.listing-actions input {
|
83 |
+
margin: 0;
|
84 |
+
}
|
85 |
+
|
86 |
+
.listing-actions input.delete-listing {
|
87 |
+
margin-left: 5px;
|
88 |
+
margin-right: 30px;
|
89 |
+
color: #ff0000;
|
90 |
+
}
|
91 |
+
|
92 |
+
.listing-actions .back-to-dir {
|
93 |
+
/* margin-left: 25px;*/
|
94 |
+
}
|
95 |
+
|
96 |
+
/*.listing-actions a {
|
97 |
+
background: none repeat scroll 0 0 #000;
|
98 |
+
border-radius: 3px 3px 3px 3px;
|
99 |
+
color: #fff;
|
100 |
+
padding: 2px 8px;
|
101 |
+
text-decoration: none;
|
102 |
+
margin-right: 8px;
|
103 |
+
text-align: center;
|
104 |
+
}
|
105 |
+
|
106 |
+
.listing-actions a.delete-listing {
|
107 |
+
margin-left: 20px;
|
108 |
+
background: #ff0000;
|
109 |
+
}*/
|
110 |
+
|
111 |
+
.wpbdp-listing .listing-details .field-value {
|
112 |
+
margin-bottom: 10px;
|
113 |
+
width: 100%;
|
114 |
+
float: none;
|
115 |
+
}
|
116 |
+
|
117 |
+
.wpbdmsingledetails .singledetailsview .field-value {
|
118 |
+
margin-bottom: 10px;
|
119 |
+
}
|
120 |
+
|
121 |
+
.field-value label {
|
122 |
+
color: #444;
|
123 |
+
font-weight: bold;
|
124 |
+
}
|
125 |
+
|
126 |
+
/* listing view > excerpt */
|
127 |
+
.wpbdp-listing-excerpt {
|
128 |
+
padding: 10px;
|
129 |
+
border-bottom: dotted 1px #ddd;
|
130 |
+
}
|
131 |
+
|
132 |
+
.wpbdp-listing-excerpt.odd { background: #eee; }
|
133 |
+
.wpbdp-listing-excerpt.sticky { background: #fff0cf; border-bottom: solid 1px #b37800; }
|
134 |
+
|
135 |
+
.wpbdp-listing-excerpt .listing-thumbnail {
|
136 |
+
float: right;
|
137 |
+
margin: 0 10px 0 0;
|
138 |
+
}
|
139 |
+
|
140 |
+
.wpbdp-listing-excerpt .listing-actions {
|
141 |
+
margin-top: 15px;
|
142 |
+
}
|
143 |
+
|
144 |
+
/* listing views > single */
|
145 |
+
.wpbdp-listing-single .listing-actions {
|
146 |
+
margin-bottom: 25px;
|
147 |
+
}
|
148 |
+
|
149 |
+
.wpbdp-listing-single .stickytag {
|
150 |
+
float: right;
|
151 |
+
margin-top: -68px;
|
152 |
+
}
|
153 |
+
|
154 |
+
.wpbdp-listing-single .stickytag img {
|
155 |
+
border: 0;
|
156 |
+
box-shadow: none;
|
157 |
+
background: transparent;
|
158 |
+
}
|
159 |
+
|
160 |
+
.wpbdp-listing-single .listing-title {
|
161 |
+
padding: 2px 8px;
|
162 |
+
background: #efefef;
|
163 |
+
border: dotted 1px #ddd;
|
164 |
+
margin-bottom: 7px;
|
165 |
+
}
|
166 |
+
|
167 |
+
.wpbdp-listing-single .listing-title h2 {
|
168 |
+
clear: none;
|
169 |
+
margin: 0;
|
170 |
+
}
|
171 |
+
|
172 |
+
.wpbdp-listing-single .main-image {
|
173 |
+
float: right;
|
174 |
+
margin-left: 10px;
|
175 |
+
padding: 5px;
|
176 |
+
}
|
177 |
+
|
178 |
+
.wpbdp-listing-single .main-image a {
|
179 |
+
position: relative !important;
|
180 |
+
}
|
181 |
+
|
182 |
+
.wpbdp-listing-single .main-image img {
|
183 |
+
border: solid 1px #333;
|
184 |
+
}
|
185 |
+
|
186 |
+
.wpbdp-listing-single .listing-details.with-image {
|
187 |
+
}
|
188 |
+
|
189 |
+
.wpbdp-listing-single .extra-images {
|
190 |
+
margin-top: 10px;
|
191 |
+
clear: both;
|
192 |
+
}
|
193 |
+
|
194 |
+
.wpbdp-listing-single .extra-images ul {
|
195 |
+
margin: 0 auto;
|
196 |
+
width: 100%;
|
197 |
+
|
198 |
+
}
|
199 |
+
|
200 |
+
.wpbdp-listing-single .extra-images ul li {
|
201 |
+
list-style-type: none;
|
202 |
+
display: inline;
|
203 |
+
margin-left: 5px;
|
204 |
+
}
|
205 |
+
|
206 |
+
.wpbdp-listing-single .extra-images ul li img {
|
207 |
+
display: inline;
|
208 |
+
vertical-align: top;
|
209 |
+
margin: 0 auto;
|
210 |
+
max-width: 150px;
|
211 |
+
border: solid 1px #333;
|
212 |
+
}
|
213 |
+
|
214 |
+
/* social fields */
|
215 |
+
|
216 |
+
.wpbdp-listing .social-fields {
|
217 |
+
margin: 20px 0;
|
218 |
+
}
|
219 |
+
|
220 |
+
.wpbdp-listing .social-field {
|
221 |
+
float: left;
|
222 |
+
margin-right: 10px;
|
223 |
+
}
|
224 |
+
|
225 |
+
/* listing contact form */
|
226 |
+
.wpbdp-listing .contact-form {
|
227 |
+
margin-top: 20px;
|
228 |
+
border-top: dotted 1px #ddd;
|
229 |
+
padding-top: 20px;
|
230 |
+
padding-left: 10px;
|
231 |
+
}
|
232 |
+
|
233 |
+
.wpbdp-listing .contact-form h3 {
|
234 |
+
margin-left: -10px;
|
235 |
+
}
|
236 |
+
|
237 |
+
.wpbdp-listing .contact-form textarea {
|
238 |
+
width: 98% !important;
|
239 |
+
}
|
240 |
+
|
241 |
+
/* listing comments form */
|
242 |
+
.wpbdp-listing .comments {
|
243 |
+
margin-top: 20px;
|
244 |
+
}
|
245 |
+
|
246 |
+
/* pages toolbar */
|
247 |
+
.wpbdp-bar {
|
248 |
+
background: #f7f7f7;
|
249 |
+
margin: 10px 0 20px 0;
|
250 |
+
padding: 5px 10px;
|
251 |
+
}
|
252 |
+
|
253 |
+
.wpbdp-bar .wpbdp-main-links {
|
254 |
+
float: left;
|
255 |
+
height: 100%;
|
256 |
+
}
|
257 |
+
|
258 |
+
.wpbdp-bar .wpbdp-search-form {
|
259 |
+
margin: 0;
|
260 |
+
padding: 0 !important;
|
261 |
+
margin-left: 50%;
|
262 |
+
}
|
263 |
+
|
264 |
+
.wpbdp-main-links a {
|
265 |
+
margin-right: 15px;
|
266 |
+
}
|
267 |
+
|
268 |
+
.wpbdp-bar .left {
|
269 |
+
float: left;
|
270 |
+
text-align: center;
|
271 |
+
}
|
272 |
+
|
273 |
+
.wpbdp-bar .right {
|
274 |
+
width: 300px;
|
275 |
+
float: right;
|
276 |
+
}
|
277 |
+
|
278 |
+
/* sort options */
|
279 |
+
.wpbdp-listings-sort-options {
|
280 |
+
font-size: 90%;
|
281 |
+
margin: 5px 0;
|
282 |
+
text-align: right;
|
283 |
+
}
|
284 |
+
|
285 |
+
.wpbdp-listings-sort-options .current {
|
286 |
+
font-weight: bold;
|
287 |
+
}
|
288 |
+
|
289 |
+
/* main page */
|
290 |
+
.wpbdp-main-page #wpbdp-categories {
|
291 |
+
clear: both;
|
292 |
+
margin-bottom: 20px;
|
293 |
+
}
|
294 |
+
|
295 |
+
ul.wpbdp-categories {
|
296 |
+
margin: 0 0 10px 15px;
|
297 |
+
padding: 0 10px;
|
298 |
+
}
|
299 |
+
|
300 |
+
ul.wpbdp-categories > li {
|
301 |
+
width: 50%;
|
302 |
+
float: left;
|
303 |
+
margin: 0;
|
304 |
+
}
|
305 |
+
|
306 |
+
@media screen and (max-width: 704px) {
|
307 |
+
ul.wpbdp-categories > li {
|
308 |
+
float: none;
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
@media screen and (max-width: 500px) {
|
313 |
+
ul.wpbdp-categories {
|
314 |
+
font-size: 90%;
|
315 |
+
}
|
316 |
+
|
317 |
+
ul.wpbdp-categories ul.children li.cat-item {
|
318 |
+
margin-left: 10px;
|
319 |
+
padding: 0;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
/* submit listing page */
|
324 |
+
.wpbdp-submit-page h3 {
|
325 |
+
margin-bottom: 10px;
|
326 |
+
}
|
327 |
+
|
328 |
+
.wpbdp-submit-page .wpbdmp {
|
329 |
+
margin: 0;
|
330 |
+
}
|
331 |
+
|
332 |
+
.wpbdp-submit-page legend {
|
333 |
+
font-size: 85%;
|
334 |
+
margin-bottom: 20px;
|
335 |
+
}
|
336 |
+
|
337 |
+
.wpbdp-submit-page .wpbdp-form-field {
|
338 |
+
margin-bottom: 8px;
|
339 |
+
}
|
340 |
+
|
341 |
+
.wpbdp-submit-page .wpbdp-form-field .wpbdmcheckboxclass checkbox {
|
342 |
+
margin-left: 0px;
|
343 |
+
}
|
344 |
+
|
345 |
+
.wpbdp-submit-page .wpbdp-form-field.required .wpbdp-form-field-label:after {
|
346 |
+
content: ' *';
|
347 |
+
font-size: 80%;
|
348 |
+
}
|
349 |
+
|
350 |
+
.wpbdp-form-field .field-description {
|
351 |
+
font-size: 90%;
|
352 |
+
color: #696969;
|
353 |
+
float: right;
|
354 |
+
}
|
355 |
+
|
356 |
+
.wpbdp-form-field span.sublabel {
|
357 |
+
font-size: 90%;
|
358 |
+
margin-left: 10px;
|
359 |
+
margin-right: 10px;
|
360 |
+
}
|
361 |
+
|
362 |
+
.wpbdp-form-field.image a.delete {
|
363 |
+
margin-left: 10px;
|
364 |
+
}
|
365 |
+
|
366 |
+
ul.validation-errors {
|
367 |
+
margin: 15px 0 15px 0;
|
368 |
+
}
|
369 |
+
|
370 |
+
ul.validation-errors li {
|
371 |
+
color: #ff0000;
|
372 |
+
margin: 3px 0px;
|
373 |
+
list-style-position: inside;
|
374 |
+
}
|
375 |
+
|
376 |
+
.wpbdp-submit-page.step-fees h4 {
|
377 |
+
background: #ddd;
|
378 |
+
color: #333;
|
379 |
+
padding: 10px;
|
380 |
+
margin-bottom: 5px;
|
381 |
+
}
|
382 |
+
|
383 |
+
.wpbdp-submit-page.step-images #image-upload-form {
|
384 |
+
margin: 15px 10px;
|
385 |
+
}
|
386 |
+
|
387 |
+
.wpbdp-submit-page.step-images .wpbdp-image {
|
388 |
+
float: left;
|
389 |
+
border-bottom: dotted 1px #efefef;
|
390 |
+
margin-right: 10px;
|
391 |
+
margin-bottom: 10px;
|
392 |
+
vertical-align: top;
|
393 |
+
}
|
394 |
+
|
395 |
+
.wpbdp-submit-page.step-images .wpbdp-image img {
|
396 |
+
vertical-align: top;
|
397 |
+
text-align: center;
|
398 |
+
max-width: 150px;
|
399 |
+
height: auto;
|
400 |
+
}
|
401 |
+
|
402 |
+
|
403 |
+
.wpbdp-submit-page.step-images .area-and-conditions #image-upload-dnd-area {
|
404 |
+
float: left;
|
405 |
+
width: 72%;
|
406 |
+
}
|
407 |
+
|
408 |
+
.wpbdp-submit-page.step-images .area-and-conditions #image-upload-conditions {
|
409 |
+
float: right;
|
410 |
+
width: 25%;
|
411 |
+
color: #666;
|
412 |
+
}
|
413 |
+
|
414 |
+
.wpbdp-submit-page.step-images .area-and-conditions #image-upload-conditions dl {
|
415 |
+
margin: 0;
|
416 |
+
}
|
417 |
+
|
418 |
+
.wpbdp-submit-page.step-images #image-upload-form-no-js {
|
419 |
+
width: 0;
|
420 |
+
height: 0;
|
421 |
+
overflow: hidden;
|
422 |
+
visibility: hidden;
|
423 |
+
}
|
424 |
+
|
425 |
+
.wpbdp-submit-page.step-images .wpbdp-image .delete-image {
|
426 |
+
color: #ff0000;
|
427 |
+
}
|
428 |
+
|
429 |
+
.wpbdp-submit-page .upgrade-to-featured-option {
|
430 |
+
border: solid 1px #666;
|
431 |
+
padding: 5px 10px;
|
432 |
+
margin: 25px 0 25px 0;
|
433 |
+
font-size: 90%;
|
434 |
+
}
|
435 |
+
|
436 |
+
/* error and status messages */
|
437 |
+
.wpbdp-msg {
|
438 |
+
font-size: 85%;
|
439 |
+
padding: 0.6em;
|
440 |
+
border: solid 1px #e6db55;
|
441 |
+
color: #555;
|
442 |
+
margin: 5px 0;
|
443 |
+
background: #fffbcc;
|
444 |
+
border-radius: 3px;
|
445 |
+
}
|
446 |
+
|
447 |
+
.wpbdp-msg.error {
|
448 |
+
background-color: #FFEBE8;
|
449 |
+
border-color: #C00;
|
450 |
+
}
|
451 |
+
|
452 |
+
/*.wpbusdirmanerroralert { color:#ff0000;font-weight:bold;font-size:14px; }*/
|
453 |
+
|
454 |
+
.wpbdp-submit-page table.fee-options {
|
455 |
+
width: 100%;
|
456 |
+
}
|
457 |
+
|
458 |
+
.wpbdp-submit-page table.fee-options th, .wpbdp-submit-page table.fee-options td {
|
459 |
+
text-align: center;
|
460 |
+
}
|
461 |
+
|
462 |
+
.wpbdp-submit-page table.fee-options .fee-selection {
|
463 |
+
width: 5%;
|
464 |
+
}
|
465 |
+
|
466 |
+
.wpbdp-submit-page table.fee-options tr.fee-option td.fee-label {
|
467 |
+
font-weight: bold;
|
468 |
+
}
|
469 |
+
|
470 |
+
.wpbdp-submit-page table.fee-options td.fee-description {
|
471 |
+
font-size: 90%;
|
472 |
+
color: #666;
|
473 |
+
}
|
474 |
+
|
475 |
+
#wpbdp-renewal-page .do-not-renew-listing {
|
476 |
+
margin: 40px 0;
|
477 |
+
border: solid 1px #eee;
|
478 |
+
font-size: 95%;
|
479 |
+
}
|
480 |
+
|
481 |
+
#wpbdp-renewal-page .do-not-renew-listing .header {
|
482 |
+
background: #bc0b0b;
|
483 |
+
color: #fff;
|
484 |
+
text-align: center;
|
485 |
+
font-weight: bold;
|
486 |
+
padding: 2px 0;
|
487 |
+
}
|
488 |
+
|
489 |
+
#wpbdp-renewal-page .do-not-renew-listing input[type="submit"] {
|
490 |
+
/*border: solid 1px #bc0b0b;*/
|
491 |
+
color: #900000;
|
492 |
+
}
|
493 |
+
|
494 |
+
.wpbdp-recaptcha-error {
|
495 |
+
color: #ff0000;
|
496 |
+
}
|
497 |
+
|
498 |
+
#wpbdp-delete-listing-page form.confirm-form {
|
499 |
+
margin-top: 30px;
|
500 |
+
}
|
501 |
+
|
502 |
+
#wpbdp-delete-listing-page input.delete-listing-confirm {
|
503 |
+
margin-left: 20px;
|
504 |
+
color: #c00;
|
505 |
+
}
|
506 |
+
|
507 |
+
/*
|
508 |
+
* Google Wallet gateway.
|
509 |
+
*/
|
510 |
+
|
511 |
+
#googlewallet-buy img {
|
512 |
+
border: none;
|
513 |
+
box-shadow: none
|
514 |
+
}
|
515 |
+
|
516 |
+
/*
|
517 |
+
* Manage Recurring Payments.
|
518 |
+
*/
|
519 |
+
table#wpbdp-manage-recurring th.listing-title,
|
520 |
+
table#wpbdp-manage-recurring td.listing-title {
|
521 |
+
min-width: 200px;
|
522 |
+
}
|
523 |
+
|
524 |
+
table#wpbdp-manage-recurring a.cancel-subscription {
|
525 |
+
color: #ff0000;
|
526 |
+
}
|
527 |
+
|
528 |
+
#wpbdp-manage-recurring-cancel dl dd {
|
529 |
+
margin-left: 10px;
|
530 |
+
}
|
531 |
+
|
532 |
+
#wpbdp-manage-recurring-cancel .cancel-instructions {
|
533 |
+
}
|
534 |
+
|
535 |
+
/* {{ Credit Card details form. */
|
536 |
+
.wpbdp-cc-form {
|
537 |
+
padding: 0;
|
538 |
+
width: 90%;
|
539 |
+
}
|
540 |
+
|
541 |
+
.wpbdp-cc-form h4 {
|
542 |
+
margin: 0;
|
543 |
+
}
|
544 |
+
|
545 |
+
.wpbdp-cc-field {
|
546 |
+
}
|
547 |
+
|
548 |
+
.wpbdp-cc-field input {
|
549 |
+
width: auto;
|
550 |
+
}
|
551 |
+
|
552 |
+
.wpbdp-cc-field label {
|
553 |
+
display: block;
|
554 |
+
font-weight: bold;
|
555 |
+
text-align: right;
|
556 |
+
padding-right: 10px;
|
557 |
+
}
|
558 |
+
|
559 |
+
/* }} */
|
core/css/wpbdp.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
form#wpbdmsearchform{padding:12px 0;text-align:center}form#wpbdmsearchform input{display:inline}form#wpbdmsearchform .wpbdmsearchbutton{margin-top:5px}form#wpbdmsearchform a.advanced-search-link{font-size:70%;display:block}#wpbdp-search-form{padding-left:10px}#wpbdp-search-form .wpbdp-search-filter{margin-bottom:10px;clear:both}#wpbdp-search-form .wpbdp-search-filter>div.label{display:block;width:40%;float:left}#wpbdp-search-form .wpbdp-search-filter>div.field{display:block;width:60%;margin-left:40%;padding-left:5px}#wpbdp-search-form .wpbdp-search-filter>div.field>input[type="text"]{width:90%}#wpbdp-search-form .wpbdp-search-filter>div.field>select{width:90%}#wpbdp-search-form input[type="submit"]{width:100px;float:none;margin:auto}.cf:before,.cf:after{content:" ";display:table}.cf:after{clear:both}.cf{*zoom:1}.wpbdp-pagination{margin:25px 0 0 0}.wpbdp-pagination .next{float:right}.listing-actions form{margin:0;padding:0;display:inline}.listing-actions input{margin:0}.listing-actions input.delete-listing{margin-left:5px;margin-right:30px;color:red}.wpbdp-listing .listing-details .field-value{margin-bottom:10px;width:100%;float:none}.wpbdmsingledetails .singledetailsview .field-value{margin-bottom:10px}.field-value label{color:#444;font-weight:bold}.wpbdp-listing-excerpt{padding:10px;border-bottom:dotted 1px #ddd}.wpbdp-listing-excerpt.odd{background:#eee}.wpbdp-listing-excerpt.sticky{background:#fff0cf;border-bottom:solid 1px #b37800}.wpbdp-listing-excerpt .listing-thumbnail{float:right;margin:0 10px 0 0}.wpbdp-listing-excerpt .listing-actions{margin-top:15px}.wpbdp-listing-single .listing-actions{margin-bottom:25px}.wpbdp-listing-single .stickytag{float:right;margin-top:-68px}.wpbdp-listing-single .stickytag img{border:0;box-shadow:none;background:transparent}.wpbdp-listing-single .listing-title{padding:2px 8px;background:#efefef;border:dotted 1px #ddd;margin-bottom:7px}.wpbdp-listing-single .listing-title h2{clear:none;margin:0}.wpbdp-listing-single .main-image{float:right;margin-left:10px;padding:5px}.wpbdp-listing-single .main-image a{position:relative !important}.wpbdp-listing-single .main-image img{border:solid 1px #333}.wpbdp-listing-single .extra-images{margin-top:10px;clear:both}.wpbdp-listing-single .extra-images ul{margin:0 auto;width:100%}.wpbdp-listing-single .extra-images ul li{list-style-type:none;display:inline;margin-left:5px}.wpbdp-listing-single .extra-images ul li img{display:inline;vertical-align:top;margin:0 auto;max-width:150px;border:solid 1px #333}.wpbdp-listing .social-fields{margin:20px 0}.wpbdp-listing .social-field{float:left;margin-right:10px}.wpbdp-listing .contact-form{margin-top:20px;border-top:dotted 1px #ddd;padding-top:20px;padding-left:10px}.wpbdp-listing .contact-form h3{margin-left:-10px}.wpbdp-listing .contact-form textarea{width:98% !important}.wpbdp-listing .comments{margin-top:20px}.wpbdp-bar{background:#f7f7f7;margin:10px 0 20px 0;padding:5px 10px}.wpbdp-bar .wpbdp-main-links{float:left;height:100%}.wpbdp-bar .wpbdp-search-form{margin:0;padding:0 !important;margin-left:50%}.wpbdp-main-links a{margin-right:15px}.wpbdp-bar .left{float:left;text-align:center}.wpbdp-bar .right{width:300px;float:right}.wpbdp-listings-sort-options{font-size:90%;margin:5px 0;text-align:right}.wpbdp-listings-sort-options .current{font-weight:bold}.wpbdp-main-page #wpbdp-categories{clear:both;margin-bottom:20px}ul.wpbdp-categories{margin:0 0 10px 15px;padding:0 10px}ul.wpbdp-categories>li{width:50%;float:left;margin:0}@media screen and (max-width:704px){ul.wpbdp-categories>li{float:none}}@media screen and (max-width:500px){ul.wpbdp-categories{font-size:90%}ul.wpbdp-categories ul.children li.cat-item{margin-left:10px;padding:0}}.wpbdp-submit-page h3{margin-bottom:10px}.wpbdp-submit-page .wpbdmp{margin:0}.wpbdp-submit-page legend{font-size:85%;margin-bottom:20px}.wpbdp-submit-page .wpbdp-form-field{margin-bottom:8px}.wpbdp-submit-page .wpbdp-form-field .wpbdmcheckboxclass checkbox{margin-left:0}.wpbdp-submit-page .wpbdp-form-field.required .wpbdp-form-field-label:after{content:' *';font-size:80%}.wpbdp-form-field .field-description{font-size:90%;color:#696969;float:right}.wpbdp-form-field span.sublabel{font-size:90%;margin-left:10px;margin-right:10px}.wpbdp-form-field.image a.delete{margin-left:10px}ul.validation-errors{margin:15px 0 15px 0}ul.validation-errors li{color:red;margin:3px 0;list-style-position:inside}.wpbdp-submit-page.step-fees h4{background:#ddd;color:#333;padding:10px;margin-bottom:5px}.wpbdp-submit-page.step-images #image-upload-form{margin:15px 10px}.wpbdp-submit-page.step-images .wpbdp-image{float:left;border-bottom:dotted 1px #efefef;margin-right:10px;margin-bottom:10px;vertical-align:top}.wpbdp-submit-page.step-images .wpbdp-image img{vertical-align:top;text-align:center;max-width:150px;height:auto}.wpbdp-submit-page.step-images .area-and-conditions #image-upload-dnd-area{float:left;width:72%}.wpbdp-submit-page.step-images .area-and-conditions #image-upload-conditions{float:right;width:25%;color:#666}.wpbdp-submit-page.step-images .area-and-conditions #image-upload-conditions dl{margin:0}.wpbdp-submit-page.step-images #image-upload-form-no-js{width:0;height:0;overflow:hidden;visibility:hidden}.wpbdp-submit-page.step-images .wpbdp-image .delete-image{color:red}.wpbdp-submit-page .upgrade-to-featured-option{border:solid 1px #666;padding:5px 10px;margin:25px 0 25px 0;font-size:90%}.wpbdp-msg{font-size:85%;padding:.6em;border:solid 1px #e6db55;color:#555;margin:5px 0;background:#fffbcc;border-radius:3px}.wpbdp-msg.error{background-color:#ffebe8;border-color:#C00}.wpbdp-submit-page table.fee-options{width:100%}.wpbdp-submit-page table.fee-options th,.wpbdp-submit-page table.fee-options td{text-align:center}.wpbdp-submit-page table.fee-options .fee-selection{width:5%}.wpbdp-submit-page table.fee-options tr.fee-option td.fee-label{font-weight:bold}.wpbdp-submit-page table.fee-options td.fee-description{font-size:90%;color:#666}#wpbdp-renewal-page .do-not-renew-listing{margin:40px 0;border:solid 1px #eee;font-size:95%}#wpbdp-renewal-page .do-not-renew-listing .header{background:#bc0b0b;color:#fff;text-align:center;font-weight:bold;padding:2px 0}#wpbdp-renewal-page .do-not-renew-listing input[type="submit"]{color:#900000}.wpbdp-recaptcha-error{color:red}#wpbdp-delete-listing-page form.confirm-form{margin-top:30px}#wpbdp-delete-listing-page input.delete-listing-confirm{margin-left:20px;color:#c00}#googlewallet-buy img{border:0;box-shadow:none}table#wpbdp-manage-recurring th.listing-title,table#wpbdp-manage-recurring td.listing-title{min-width:200px}table#wpbdp-manage-recurring a.cancel-subscription{color:red}#wpbdp-manage-recurring-cancel dl dd{margin-left:10px}.wpbdp-cc-form{padding:0;width:90%}.wpbdp-cc-form h4{margin:0}.wpbdp-cc-field input{width:auto}.wpbdp-cc-field label{display:block;font-weight:bold;text-align:right;padding-right:10px}
|
core/debugging.php
ADDED
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPBDP_Debugging {
|
3 |
+
|
4 |
+
private static $debug = false;
|
5 |
+
private static $messages = array();
|
6 |
+
|
7 |
+
public static function is_debug_on() {
|
8 |
+
return self::$debug;
|
9 |
+
}
|
10 |
+
|
11 |
+
public static function debug_on() {
|
12 |
+
self::$debug = true;
|
13 |
+
|
14 |
+
error_reporting(E_ALL | E_DEPRECATED);
|
15 |
+
|
16 |
+
// Disable our debug util for AJAX requests in order to be able to see the errors.
|
17 |
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
|
18 |
+
return;
|
19 |
+
|
20 |
+
// @ini_set('display_errors', '1');
|
21 |
+
set_error_handler(array('WPBDP_Debugging', '_php_error_handler'));
|
22 |
+
|
23 |
+
add_action( 'wp_enqueue_scripts', array( 'WPBDP_Debugging', '_enqueue_scripts' ) );
|
24 |
+
add_action( 'admin_enqueue_scripts', array( 'WPBDP_Debugging', '_enqueue_scripts' ) );
|
25 |
+
|
26 |
+
add_action('admin_footer', array('WPBDP_Debugging', '_debug_bar_footer'), 99999);
|
27 |
+
add_action('wp_footer', array('WPBDP_Debugging', '_debug_bar_footer'), 99999);
|
28 |
+
}
|
29 |
+
|
30 |
+
public static function _enqueue_scripts() {
|
31 |
+
wp_enqueue_script( 'wpbdp-debugging-js',
|
32 |
+
WPBDP_URL . 'core/js/debug.min.js',
|
33 |
+
array( 'jquery' ),
|
34 |
+
null,
|
35 |
+
true );
|
36 |
+
wp_enqueue_style( 'wpbdp-debugging-styles', WPBDP_URL . 'core/css/debug.min.css' );
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function _php_error_handler($errno, $errstr, $file, $line, $context) {
|
40 |
+
static $errno_to_string = array(
|
41 |
+
E_ERROR => 'error',
|
42 |
+
E_WARNING => 'warning',
|
43 |
+
E_NOTICE => 'notice',
|
44 |
+
E_USER_ERROR => 'user-error',
|
45 |
+
E_USER_WARNING => 'user-warning',
|
46 |
+
E_USER_NOTICE => 'user-notice',
|
47 |
+
E_DEPRECATED => 'deprecated'
|
48 |
+
);
|
49 |
+
|
50 |
+
self::add_debug_msg( $errstr,
|
51 |
+
isset( $errno_to_string[ $errno ] ) ? 'php-' . $errno_to_string[ $errno ] : 'php',
|
52 |
+
array( 'file' => $file,
|
53 |
+
'line' => $line) );
|
54 |
+
}
|
55 |
+
|
56 |
+
public static function debug_off() {
|
57 |
+
self::$debug = false;
|
58 |
+
|
59 |
+
remove_action('admin_footer', array('WPBDP_Debugging', '_debug_bar_footer'), 99999);
|
60 |
+
remove_action('wp_footer', array('WPBDP_Debugging', '_debug_bar_footer'), 99999);
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function register_dummy_gateway( &$payments ) {
|
64 |
+
if ( ! self::$debug )
|
65 |
+
return;
|
66 |
+
|
67 |
+
require_once ( WPBDP_PATH . 'core/gateways-dummy.php' );
|
68 |
+
$payments->register_gateway( 'dummy', 'WPBDP_Dummy_Gateway' );
|
69 |
+
}
|
70 |
+
|
71 |
+
public static function _debug_bar_footer() {
|
72 |
+
if (!self::$debug)
|
73 |
+
return;
|
74 |
+
|
75 |
+
global $wpdb;
|
76 |
+
$queries = $wpdb->queries;
|
77 |
+
|
78 |
+
if (!self::$messages && !$queries)
|
79 |
+
return;
|
80 |
+
|
81 |
+
echo '<div id="wpbdp-debugging">';
|
82 |
+
echo '<ul class="tab-selector">';
|
83 |
+
echo '<li class="active"><a href="#logging">Logging</a></li>';
|
84 |
+
echo '<li><a href="#wpdbqueries">$wpdb queries</a></li>';
|
85 |
+
echo '</ul>';
|
86 |
+
echo '<div class="tab" id="wpbdp-debugging-tab-logging">';
|
87 |
+
echo '<table>';
|
88 |
+
|
89 |
+
foreach (self::$messages as $item) {
|
90 |
+
$time = explode( ' ', $item['timestamp'] );
|
91 |
+
|
92 |
+
echo '<tr class="' . $item['type'] . '">';
|
93 |
+
echo '<td class="handle">»</td>';
|
94 |
+
echo '<td class="timestamp">' . date('H:i:s', $time[1]) . '</td>';
|
95 |
+
|
96 |
+
echo '<td class="type">' . $item['type'] . '</td>';
|
97 |
+
echo '<td class="message">' . $item['message'] . '</td>';
|
98 |
+
|
99 |
+
if ($item['context']) {
|
100 |
+
echo '<td class="context">' . $item['context']['function'] . '</td>';
|
101 |
+
echo '<td class="file">' . basename($item['context']['file']) . ':' . $item['context']['line'] . '</td>';
|
102 |
+
} else {
|
103 |
+
echo '<td class="context"></td><td class="file"></td>';
|
104 |
+
}
|
105 |
+
echo '</tr>';
|
106 |
+
}
|
107 |
+
|
108 |
+
echo '</table>';
|
109 |
+
echo '</div>';
|
110 |
+
|
111 |
+
echo '<div class="tab" id="wpbdp-debugging-tab-wpdbqueries">';
|
112 |
+
if ( !$queries ) {
|
113 |
+
echo 'No SQL queries were logged.';
|
114 |
+
} else {
|
115 |
+
echo '<table>';
|
116 |
+
|
117 |
+
foreach ( $queries as $q ) {
|
118 |
+
echo '<tr class="wpdbquery">';
|
119 |
+
echo '<td class="handle">»</td>';
|
120 |
+
echo '<td class="query">';
|
121 |
+
echo $q[0];
|
122 |
+
echo '<div class="extradata">';
|
123 |
+
echo '<dl>';
|
124 |
+
echo '<dt>Time Spent:</dt><dd>' . $q[1] . '</dd>';
|
125 |
+
echo '<dt>Backtrace:</dt><dd>' . $q[2] . '</dd>';
|
126 |
+
echo '</dl>';
|
127 |
+
echo '</div>';
|
128 |
+
echo '</td>';
|
129 |
+
echo '</tr>';
|
130 |
+
}
|
131 |
+
|
132 |
+
echo '</table>';
|
133 |
+
}
|
134 |
+
echo '</div>';
|
135 |
+
echo '</div>';
|
136 |
+
}
|
137 |
+
|
138 |
+
private static function _extract_context($stack) {
|
139 |
+
if ( !is_array( $stack ) || empty( $stack ) )
|
140 |
+
return array();
|
141 |
+
|
142 |
+
$context = array( 'class' => '', 'file' => '', 'function' => '', 'line' => '' );
|
143 |
+
|
144 |
+
foreach ( $stack as $i => &$item ) {
|
145 |
+
if ( ( isset( $item['class'] ) && $item['class'] == 'WPBDP_Debugging' ) || ( isset( $item['file'] ) && $item['file'] == __FILE__ ) )
|
146 |
+
continue;
|
147 |
+
|
148 |
+
if ( isset( $item['function'] ) && in_array( $item['function'], array( 'wpbdp_log', 'wpbdp_debug', 'wpbdp_log_deprecated' ) ) ) {
|
149 |
+
$context['file'] = $item['file'];
|
150 |
+
$context['line'] = $item['line'];
|
151 |
+
$context['function'] = $item['function'];
|
152 |
+
|
153 |
+
$i2 = current( $stack );
|
154 |
+
$context['function'] = $i2['function'];
|
155 |
+
break;
|
156 |
+
} else {
|
157 |
+
$context['file'] = $item['file'];
|
158 |
+
$context['line'] = $item['line'];
|
159 |
+
$context['stack'] = $stack;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
return $context;
|
164 |
+
}
|
165 |
+
|
166 |
+
private static function add_debug_msg($msg, $type='debug', $context=null) {
|
167 |
+
self::$messages[] = array( 'timestamp' => microtime(),
|
168 |
+
'message' => $msg,
|
169 |
+
'type' => $type,
|
170 |
+
'context' => wpbdp_starts_with( $type, 'php', false ) ? $context : self::_extract_context($context),
|
171 |
+
);
|
172 |
+
}
|
173 |
+
|
174 |
+
private static function _var_dump($var) {
|
175 |
+
if ( is_bool( $var ) || is_int( $var ) || ( is_string( $var ) && empty( $var ) ) )
|
176 |
+
return var_export( $var, true );
|
177 |
+
|
178 |
+
return print_r($var, true);
|
179 |
+
}
|
180 |
+
|
181 |
+
/* API */
|
182 |
+
|
183 |
+
public static function debug() {
|
184 |
+
if (self::$debug) {
|
185 |
+
foreach (func_get_args() as $var)
|
186 |
+
self::add_debug_msg(self::_var_dump($var), 'debug', debug_backtrace());
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
public static function debug_e() {
|
191 |
+
$ret = '';
|
192 |
+
|
193 |
+
foreach (func_get_args() as $arg)
|
194 |
+
$ret .= self::_var_dump($arg) . "\n";
|
195 |
+
|
196 |
+
wp_die(sprintf('<pre>%s</pre>', $ret), '');
|
197 |
+
}
|
198 |
+
|
199 |
+
public static function log($msg, $type='info') {
|
200 |
+
self::add_debug_msg($msg, sprintf('log-%s', $type), debug_backtrace());
|
201 |
+
}
|
202 |
+
|
203 |
+
}
|
204 |
+
|
205 |
+
function wpbdp_log($msg, $type='info') {
|
206 |
+
call_user_func(array('WPBDP_Debugging', 'log'), $msg, $type);
|
207 |
+
}
|
208 |
+
|
209 |
+
function wpbdp_log_deprecated() {
|
210 |
+
wpbdp_log('Deprecated function called.', 'deprecated');
|
211 |
+
}
|
212 |
+
|
213 |
+
function wpbdp_debug() {
|
214 |
+
$args = func_get_args();
|
215 |
+
call_user_func_array(array('WPBDP_Debugging', 'debug'), $args);
|
216 |
+
}
|
217 |
+
|
218 |
+
function wpbdp_debug_e() {
|
219 |
+
$args = func_get_args();
|
220 |
+
call_user_func_array(array('WPBDP_Debugging', 'debug_e'), $args);
|
221 |
+
}
|
222 |
+
|
223 |
+
|
224 |
+
add_action( 'wpbdp_register_gateways', array( 'WPBDP_Debugging', 'register_dummy_gateway' ) );
|
core/form-fields-types.php
ADDED
@@ -0,0 +1,1051 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Standard form field types.
|
4 |
+
*/
|
5 |
+
|
6 |
+
require_once( WPBDP_PATH . '/core/class-form-field-type.php' );
|
7 |
+
|
8 |
+
|
9 |
+
class WPBDP_FieldTypes_TextField extends WPBDP_Form_Field_Type {
|
10 |
+
|
11 |
+
public function __construct() {
|
12 |
+
parent::__construct( _x('Textfield', 'form-fields api', 'WPBDM') );
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get_id() {
|
16 |
+
return 'textfield';
|
17 |
+
}
|
18 |
+
|
19 |
+
public function convert_input( &$field, $input ) {
|
20 |
+
$input = strval( $input );
|
21 |
+
|
22 |
+
if ( $field->get_association() == 'tags' ) {
|
23 |
+
return explode( ',', $input );
|
24 |
+
}
|
25 |
+
|
26 |
+
return $input;
|
27 |
+
}
|
28 |
+
|
29 |
+
public function get_field_value( &$field, $value ) {
|
30 |
+
$value = parent::get_field_value( $field, $value );
|
31 |
+
|
32 |
+
if ( $field->get_association() == 'tags' ) {
|
33 |
+
$tags = implode( ',', $value );
|
34 |
+
return $tags;
|
35 |
+
}
|
36 |
+
|
37 |
+
return $value;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
41 |
+
if ( is_array( $value ) )
|
42 |
+
$value = implode( ',', $value );
|
43 |
+
|
44 |
+
$html = '';
|
45 |
+
|
46 |
+
if ( $field->has_validator( 'date' ) )
|
47 |
+
$html .= _x( 'Format 01/31/1969', 'form-fields api', 'WPBDM' );
|
48 |
+
|
49 |
+
$html .= sprintf( '<input type="text" id="%s" name="%s" class="intextbox %s" value="%s" />',
|
50 |
+
'wpbdp-field-' . $field->get_id(),
|
51 |
+
'listingfields[' . $field->get_id() . ']',
|
52 |
+
$field->is_required() ? 'inselect required' : 'inselect',
|
53 |
+
esc_attr( $value ) );
|
54 |
+
|
55 |
+
return $html;
|
56 |
+
}
|
57 |
+
|
58 |
+
public function get_supported_associations() {
|
59 |
+
return array( 'title', 'excerpt', 'tags', 'meta' );
|
60 |
+
}
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
class WPBDP_FieldTypes_URL extends WPBDP_Form_Field_Type {
|
65 |
+
|
66 |
+
public function __construct() {
|
67 |
+
parent::__construct( _x( 'URL Field', 'form-fields api', 'WPBDM' ) );
|
68 |
+
}
|
69 |
+
|
70 |
+
public function get_id() {
|
71 |
+
return 'url';
|
72 |
+
}
|
73 |
+
|
74 |
+
public function get_supported_associations() {
|
75 |
+
return array( 'meta' );
|
76 |
+
}
|
77 |
+
|
78 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
79 |
+
if ( $association != 'meta' )
|
80 |
+
return '';
|
81 |
+
|
82 |
+
$settings = array();
|
83 |
+
|
84 |
+
$settings['new-window'][] = _x( 'Open link in a new window?', 'form-fields admin', 'WPBDM' );
|
85 |
+
$settings['new-window'][] = '<input type="checkbox" value="1" name="field[x_open_in_new_window]" ' . ( $field && $field->data( 'open_in_new_window' ) ? ' checked="checked"' : '' ) . ' />';
|
86 |
+
|
87 |
+
$settings['nofollow'][] = _x( 'Use rel="nofollow" when displaying the link?', 'form-fields admin', 'WPBDM' );
|
88 |
+
$settings['nofollow'][] = '<input type="checkbox" value="1" name="field[x_use_nofollow]" ' . ( $field && $field->data( 'use_nofollow' ) ? ' checked="checked"' : '' ) . ' />';
|
89 |
+
|
90 |
+
return self::render_admin_settings( $settings );
|
91 |
+
}
|
92 |
+
|
93 |
+
public function process_field_settings( &$field ) {
|
94 |
+
if ( array_key_exists( 'x_open_in_new_window', $_POST['field'] ) ) {
|
95 |
+
$open_in_new_window = (bool) intval( $_POST['field']['x_open_in_new_window'] );
|
96 |
+
$field->set_data( 'open_in_new_window', $open_in_new_window );
|
97 |
+
}
|
98 |
+
|
99 |
+
if ( array_key_exists( 'x_use_nofollow', $_POST['field'] ) ) {
|
100 |
+
$use_nofollow = (bool) intval( $_POST['field']['x_use_nofollow'] );
|
101 |
+
$field->set_data( 'use_nofollow', $use_nofollow );
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
public function setup_field( &$field ) {
|
106 |
+
$field->add_validator( 'url' );
|
107 |
+
}
|
108 |
+
|
109 |
+
public function get_field_value( &$field, $post_id ) {
|
110 |
+
$value = parent::get_field_value( $field, $post_id );
|
111 |
+
|
112 |
+
if ( $value === null )
|
113 |
+
return array( '', '' );
|
114 |
+
|
115 |
+
if ( !is_array( $value ) )
|
116 |
+
return array( $value, $value );
|
117 |
+
|
118 |
+
if ( !isset( $value[1] ) || empty( $value[1] ) )
|
119 |
+
$value[1] = $value[0];
|
120 |
+
|
121 |
+
return $value;
|
122 |
+
}
|
123 |
+
|
124 |
+
public function get_field_html_value( &$field, $post_id ) {
|
125 |
+
$value = $field->value( $post_id );
|
126 |
+
|
127 |
+
return sprintf( '<a href="%s" rel="%s" target="%s" title="%s">%s</a>',
|
128 |
+
esc_url( $value[0] ),
|
129 |
+
$field->data( 'use_nofollow' ) == true ? 'nofollow': '',
|
130 |
+
$field->data( 'open_in_new_window' ) == true ? '_blank' : '_self',
|
131 |
+
esc_attr( $value[1] ),
|
132 |
+
esc_attr( $value[1] ) );
|
133 |
+
}
|
134 |
+
|
135 |
+
public function get_field_plain_value( &$field, $post_id ) {
|
136 |
+
$value = $field->value( $post_id );
|
137 |
+
return $value[0];
|
138 |
+
}
|
139 |
+
|
140 |
+
public function convert_csv_input( &$field, $input = '' ) {
|
141 |
+
$input = str_replace( array( '"', '\'' ), '', $input );
|
142 |
+
$parts = explode( ',', $input );
|
143 |
+
|
144 |
+
if ( 1 == count( $parts ) )
|
145 |
+
return array( $parts[0], $parts[0] );
|
146 |
+
|
147 |
+
return array( $parts[0], $parts[1] );
|
148 |
+
}
|
149 |
+
|
150 |
+
public function get_field_csv_value( &$field, $post_id ) {
|
151 |
+
$value = $field->value( $post_id );
|
152 |
+
|
153 |
+
if ( is_array( $value ) && count( $value ) > 1 ) {
|
154 |
+
return sprintf( '%s,%s', $value[0], $value[1] );
|
155 |
+
}
|
156 |
+
|
157 |
+
return is_array( $value ) ? $value[0] : '';
|
158 |
+
}
|
159 |
+
|
160 |
+
public function convert_input( &$field, $input ) {
|
161 |
+
if ( $input === null )
|
162 |
+
return array( '', '' );
|
163 |
+
|
164 |
+
if ( !is_array( $input ) )
|
165 |
+
return array( $input, $input );
|
166 |
+
|
167 |
+
return $input;
|
168 |
+
}
|
169 |
+
|
170 |
+
public function is_empty_value( $value ) {
|
171 |
+
return empty( $value[0] );
|
172 |
+
}
|
173 |
+
|
174 |
+
public function store_field_value( &$field, $post_id, $value ) {
|
175 |
+
if ( !is_array( $value ) || $value[0] == '' )
|
176 |
+
$value = null;
|
177 |
+
|
178 |
+
parent::store_field_value( $field, $post_id, $value );
|
179 |
+
}
|
180 |
+
|
181 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
182 |
+
if ( $context == 'search' ) {
|
183 |
+
global $wpbdp;
|
184 |
+
return $wpbdp->formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value[0], $context, $extra );
|
185 |
+
}
|
186 |
+
|
187 |
+
$html = '';
|
188 |
+
$html .= sprintf( '<span class="sublabel">%s</span>', _x( 'URL:', 'form-fields api', 'WPBDM' ) );
|
189 |
+
$html .= sprintf( '<input type="text" id="%s" name="%s" class="intextbox %s" value="%s" />',
|
190 |
+
'wpbdp-field-' . $field->get_id(),
|
191 |
+
'listingfields[' . $field->get_id() . '][0]',
|
192 |
+
$field->is_required() ? 'inselect required' : 'inselect',
|
193 |
+
esc_attr( $value[0] ) );
|
194 |
+
|
195 |
+
$html .= sprintf( '<span class="sublabel">%s</span>', _x( 'Link Text (optional):', 'form-fields api', 'WPBDM' ) );
|
196 |
+
$html .= sprintf( '<input type="text" id="%s" name="%s" class="intextbox" value="%s" placeholder="" />',
|
197 |
+
'wpbdp-field-' . $field->get_id() . '-title',
|
198 |
+
'listingfields[' . $field->get_id() . '][1]',
|
199 |
+
esc_attr( $value[1] ) );
|
200 |
+
|
201 |
+
return $html;
|
202 |
+
}
|
203 |
+
|
204 |
+
}
|
205 |
+
|
206 |
+
class WPBDP_FieldTypes_Select extends WPBDP_Form_Field_Type {
|
207 |
+
|
208 |
+
private $multiselect = false;
|
209 |
+
|
210 |
+
public function __construct() {
|
211 |
+
parent::__construct( _x('Select List', 'form-fields api', 'WPBDM') );
|
212 |
+
}
|
213 |
+
|
214 |
+
public function get_id() {
|
215 |
+
return 'select';
|
216 |
+
}
|
217 |
+
|
218 |
+
public function set_multiple( $val ) {
|
219 |
+
$this->multiselect = (bool) $val;
|
220 |
+
}
|
221 |
+
|
222 |
+
public function is_multiple() {
|
223 |
+
return $this->multiselect;
|
224 |
+
}
|
225 |
+
|
226 |
+
public function convert_input( &$field, $input ) {
|
227 |
+
$input = is_null( $input ) ? array() : $input;
|
228 |
+
$res = is_array( $input ) ? $input : array( $input );
|
229 |
+
|
230 |
+
if ( $field->get_association() == 'category' ) {
|
231 |
+
$res = array_map( 'intval', $res );
|
232 |
+
}
|
233 |
+
|
234 |
+
return $res;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* @since 3.4.1
|
239 |
+
*/
|
240 |
+
public function convert_csv_input( &$field, $input = '' ) {
|
241 |
+
if ( 'meta' != $field->get_association() )
|
242 |
+
return $this->convert_input( $field, $input );
|
243 |
+
|
244 |
+
if ( ! $input )
|
245 |
+
return array();
|
246 |
+
|
247 |
+
if ( ! $this->is_multiple() )
|
248 |
+
return array( str_replace( ',', '', $input ) );
|
249 |
+
|
250 |
+
return explode( ',', $input );
|
251 |
+
}
|
252 |
+
|
253 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
254 |
+
$options = $field->data( 'options' ) ? $field->data( 'options' ) : array();
|
255 |
+
$value = is_array( $value ) ? $value : array( $value );
|
256 |
+
|
257 |
+
$html = '';
|
258 |
+
|
259 |
+
if ( $field->get_association() == 'tags' && !$options ) {
|
260 |
+
$tags = get_terms( WPBDP_TAGS_TAX, array( 'hide_empty' => false, 'fields' => 'names' ) );
|
261 |
+
$options = array_combine( $tags, $tags );
|
262 |
+
}
|
263 |
+
|
264 |
+
if ( $field->get_association() == 'category' ) {
|
265 |
+
$html .= wp_dropdown_categories( array(
|
266 |
+
'taxonomy' => $field->get_association() == 'tags' ? WPBDP_TAGS_TAX : WPBDP_CATEGORY_TAX,
|
267 |
+
'show_option_none' => $context == 'search' ? ( $this->is_multiple() ? _x( '-- Choose Terms --', 'form-fields-api category-select', 'WPBDM' ) : _x( '-- Choose One --', 'form-fields-api category-select', 'WPBDM' ) ) : null,
|
268 |
+
'orderby' => wpbdp_get_option( 'categories-order-by' ),
|
269 |
+
'selected' => ( $this->is_multiple() ? null : ( $value ? $value[0] : null ) ),
|
270 |
+
'order' => wpbdp_get_option('categories-sort' ),
|
271 |
+
'hide_empty' => $context == 'search' && wpbdp_get_option( 'hide-empty-categories' ) ? 1 : 0,
|
272 |
+
'hierarchical' => 1,
|
273 |
+
'echo' => 0,
|
274 |
+
'id' => 'wpbdp-field-' . $field->get_id(),
|
275 |
+
'name' => 'listingfields[' . $field->get_id() . ']',
|
276 |
+
'class' => $field->is_required() ? 'inselect required' : 'inselect'
|
277 |
+
) );
|
278 |
+
|
279 |
+
if ( $this->is_multiple() ) {
|
280 |
+
$html = preg_replace( "/\\<select(.*)name=('|\")(.*)('|\")(.*)\\>/uiUs",
|
281 |
+
"<select name=\"$3[]\" multiple=\"multiple\" $1 $5>",
|
282 |
+
$html );
|
283 |
+
|
284 |
+
if ($value) {
|
285 |
+
foreach ( $value as $catid ) {
|
286 |
+
$html = preg_replace( "/\\<option(.*)value=('|\"){$catid}('|\")(.*)\\>/uiU",
|
287 |
+
"<option value=\"{$catid}\" selected=\"selected\" $1 $4>",
|
288 |
+
$html );
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
+
} else {
|
293 |
+
$html .= sprintf( '<select id="%s" name="%s" %s class="%s %s">',
|
294 |
+
'wpbdp-field-' . $field->get_id(),
|
295 |
+
'listingfields[' . $field->get_id() . ']' . ( $this->is_multiple() ? '[]' : '' ),
|
296 |
+
$this->is_multiple() ? 'multiple="multiple"' : '',
|
297 |
+
'inselect',
|
298 |
+
$field->is_required() ? 'required' : '');
|
299 |
+
|
300 |
+
if ( $field->data( 'empty_on_search' ) && $context == 'search' ) {
|
301 |
+
$html .= sprintf( '<option value="-1">%s</option>',
|
302 |
+
_x( '-- Choose One --', 'form-fields-api category-select', 'WPBDM' ) );
|
303 |
+
}
|
304 |
+
|
305 |
+
foreach ( $options as $option => $label ) {
|
306 |
+
$option_data = array( 'label' => $label,
|
307 |
+
'value' => esc_attr( $option ),
|
308 |
+
'attributes' => array() );
|
309 |
+
|
310 |
+
if ( in_array( $option, $value ) )
|
311 |
+
$option_data['attributes']['selected'] = 'selected';
|
312 |
+
|
313 |
+
$option_data = apply_filters( 'wpbdp_form_field_select_option', $option_data, $field );
|
314 |
+
|
315 |
+
$html .= sprintf( '<option value="%s" %s>%s</option>',
|
316 |
+
esc_attr( $option_data['value'] ),
|
317 |
+
$this->html_attributes( $option_data['attributes'], array( 'value', 'class' ) ),
|
318 |
+
esc_attr( $option_data['label'] ) );
|
319 |
+
}
|
320 |
+
|
321 |
+
$html .= '</select>';
|
322 |
+
}
|
323 |
+
|
324 |
+
return $html;
|
325 |
+
}
|
326 |
+
|
327 |
+
public function get_supported_associations() {
|
328 |
+
return array( 'category', 'tags', 'meta', 'region' );
|
329 |
+
}
|
330 |
+
|
331 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
332 |
+
if ( $association != 'meta' && $association != 'tags' )
|
333 |
+
return '';
|
334 |
+
|
335 |
+
$settings = array();
|
336 |
+
|
337 |
+
$settings['options'][] = _x( 'Field Options (for select lists, radio buttons and checkboxes).', 'form-fields admin', 'WPBDM' ) . '<span class="description">(required)</span>';
|
338 |
+
|
339 |
+
$content = '<span class="description">Comma (,) separated list of options</span><br />';
|
340 |
+
$content .= '<textarea name="field[x_options]" cols="50" rows="2">';
|
341 |
+
|
342 |
+
if ( $field && $field->data( 'options' ) )
|
343 |
+
$content .= implode( ',', $field->data( 'options' ) );
|
344 |
+
$content .= '</textarea>';
|
345 |
+
|
346 |
+
$settings['options'][] = $content;
|
347 |
+
|
348 |
+
$settings['empty_on_search'][] = _x('Allow empty selection on search?', 'form-fields admin', 'WPBDM');
|
349 |
+
|
350 |
+
$content = '<span class="description">Empty search selection means users can make this field optional in searching. Turn it off if the field must always be searched on.</span><br />';
|
351 |
+
$content .= '<input type="checkbox" value="1" name="field[x_empty_on_search]" ' . ( !$field ? ' checked="checked"' : ($field->data( 'empty_on_search' ) ? ' checked="checked"' : '') ) . ' />';
|
352 |
+
|
353 |
+
$settings['empty_on_search'][] = $content;
|
354 |
+
|
355 |
+
return self::render_admin_settings( $settings );
|
356 |
+
}
|
357 |
+
|
358 |
+
public function process_field_settings( &$field ) {
|
359 |
+
if ( !array_key_exists( 'x_options', $_POST['field'] ) )
|
360 |
+
return;
|
361 |
+
|
362 |
+
$options = trim( $_POST['field']['x_options'] );
|
363 |
+
|
364 |
+
if ( !$options && $field->get_association() != 'tags' )
|
365 |
+
return new WP_Error( 'wpbdp-invalid-settings', _x( 'Field list of options is required.', 'form-fields admin', 'WPBDM' ) );
|
366 |
+
|
367 |
+
$field->set_data( 'options', !empty( $options ) ? explode( ',', $options ) : array() );
|
368 |
+
|
369 |
+
if ( array_key_exists( 'x_empty_on_search', $_POST['field'] ) ) {
|
370 |
+
$empty_on_search = (bool) intval( $_POST['field']['x_empty_on_search'] );
|
371 |
+
$field->set_data( 'empty_on_search', $empty_on_search );
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
public function store_field_value( &$field, $post_id, $value ) {
|
376 |
+
if ( $this->is_multiple() && $field->get_association() == 'meta' ) {
|
377 |
+
if ( $value )
|
378 |
+
$value = implode( "\t", is_array( $value ) ? $value : array( $value ) );
|
379 |
+
}
|
380 |
+
|
381 |
+
parent::store_field_value( $field, $post_id, $value );
|
382 |
+
}
|
383 |
+
|
384 |
+
public function get_field_value( &$field, $post_id ) {
|
385 |
+
$value = parent::get_field_value( $field, $post_id );
|
386 |
+
|
387 |
+
if ( $this->is_multiple() && $field->get_association() == 'meta' ) {
|
388 |
+
if ( !empty( $value ) )
|
389 |
+
return explode( "\t", $value );
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( !$value )
|
393 |
+
return array();
|
394 |
+
|
395 |
+
$value = is_array( $value ) ? $value : array( $value );
|
396 |
+
return $value;
|
397 |
+
}
|
398 |
+
|
399 |
+
public function get_field_html_value( &$field, $post_id ) {
|
400 |
+
if ( $field->get_association() == 'meta' ) {
|
401 |
+
$value = $field->value( $post_id );
|
402 |
+
|
403 |
+
return esc_attr( implode( ', ', $value ) );
|
404 |
+
}
|
405 |
+
|
406 |
+
return parent::get_field_html_value( $field, $post_id );
|
407 |
+
}
|
408 |
+
|
409 |
+
public function get_field_plain_value( &$field, $post_id ) {
|
410 |
+
$value = $field->value( $post_id );
|
411 |
+
|
412 |
+
if ( $field->get_association() == 'category' || $field->get_association() == 'tags' ) {
|
413 |
+
$term_names = get_terms( $field->get_association() == 'category' ? WPBDP_CATEGORY_TAX : WPBDP_TAGS_TAX,
|
414 |
+
array( 'include' => $value, 'hide_empty' => 0, 'fields' => 'names' ) );
|
415 |
+
|
416 |
+
return join( ', ', $term_names );
|
417 |
+
} elseif ( $field->get_association() == 'meta' ) {
|
418 |
+
return esc_attr( implode( ', ', $value ) );
|
419 |
+
}
|
420 |
+
|
421 |
+
return $value;
|
422 |
+
}
|
423 |
+
|
424 |
+
/**
|
425 |
+
* @since 3.4.1
|
426 |
+
*/
|
427 |
+
public function get_field_csv_value( &$field, $post_id ) {
|
428 |
+
if ( 'meta' != $field->get_association() )
|
429 |
+
return $field->plain_value( $post_id );
|
430 |
+
|
431 |
+
$value = $field->value( $post_id );
|
432 |
+
return esc_attr( implode( ',', $value ) );
|
433 |
+
}
|
434 |
+
|
435 |
+
}
|
436 |
+
|
437 |
+
class WPBDP_FieldTypes_TextArea extends WPBDP_Form_Field_Type {
|
438 |
+
|
439 |
+
public function __construct() {
|
440 |
+
parent::__construct( _x('Textarea', 'form-fields api', 'WPBDM') );
|
441 |
+
}
|
442 |
+
|
443 |
+
public function get_id() {
|
444 |
+
return 'textarea';
|
445 |
+
}
|
446 |
+
|
447 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
448 |
+
// render textareas as textfields when searching
|
449 |
+
if ( $context == 'search' ) {
|
450 |
+
global $wpbdp;
|
451 |
+
return $wpbdp->formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value, $context, $extra );
|
452 |
+
}
|
453 |
+
|
454 |
+
return sprintf('<textarea id="%s" name="%s" class="intextarea textarea %s">%s</textarea>',
|
455 |
+
'wpbdp-field-' . $field->get_id(),
|
456 |
+
'listingfields[' . $field->get_id() . ']',
|
457 |
+
$field->is_required() ? 'required' : '',
|
458 |
+
$value ? esc_attr( $value ) : '' );
|
459 |
+
|
460 |
+
}
|
461 |
+
|
462 |
+
public function get_supported_associations() {
|
463 |
+
return array( 'title', 'excerpt', 'content', 'meta' );
|
464 |
+
}
|
465 |
+
|
466 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
467 |
+
$settings = array();
|
468 |
+
|
469 |
+
$settings['allow_html'][] = _x( 'Allow HTML input for this field?', 'form-fields admin', 'WPBDM' );
|
470 |
+
$settings['allow_html'][] = '<input type="checkbox" value="1" name="field[allow_html]" ' . ( $field && $field->data( 'allow_html' ) ? ' checked="checked"' : '' ) . ' />';
|
471 |
+
|
472 |
+
if ( ( $field && $field->get_association() == 'content' ) || ( $association == 'content' ) ) {
|
473 |
+
$settings['allow_shortcodes'][] = _x( 'Allow WordPress shortcodes in this field?', 'form-fields admin', 'WPBDM' );
|
474 |
+
$settings['allow_shortcodes'][] = '<input type="checkbox" value="1" name="field[allow_shortcodes]" ' . ( $field && $field->data( 'allow_shortcodes' ) ? ' checked="checked"' : '' ) . ' />';
|
475 |
+
|
476 |
+
//$desc = _x( 'Useful for integrating with some plugins.', 'form-fields admin', 'WPBDM' ) . '<br />';
|
477 |
+
$desc = _x( '<b>Advanced users only!</b> Unless you\'ve been told to change this, don\'t switch it unless you know what you\'re doing.', 'form-fields admin', 'WPBDM' );
|
478 |
+
$settings['allow_filters'][] = _x( 'Apply "the_content" filter before displaying this field?', 'form-fields admin', 'WPBDM' );
|
479 |
+
$settings['allow_filters'][] = '<input type="checkbox" value="1" name="field[allow_filters]" ' . ( $field && $field->data( 'allow_filters' ) ? ' checked="checked"' : '' ) . ' /> <span class="description">' . $desc . '</span>';
|
480 |
+
}
|
481 |
+
|
482 |
+
return self::render_admin_settings( $settings );
|
483 |
+
}
|
484 |
+
|
485 |
+
public function process_field_settings( &$field ) {
|
486 |
+
$field->set_data( 'allow_html', isset( $_POST['field']['allow_html'] ) ? (bool) intval( $_POST['field']['allow_html'] ) : false );
|
487 |
+
$field->set_data( 'allow_filters', isset( $_POST['field']['allow_filters'] ) ? (bool) intval( $_POST['field']['allow_filters'] ) : false );
|
488 |
+
$field->set_data( 'allow_shortcodes', isset( $_POST['field']['allow_shortcodes'] ) ? (bool) intval( $_POST['field']['allow_shortcodes'] ) : false );
|
489 |
+
}
|
490 |
+
|
491 |
+
public function get_field_html_value( &$field, $post_id ) {
|
492 |
+
$value = $field->value( $post_id );
|
493 |
+
|
494 |
+
if ( $field->data( 'allow_html' ) ) {
|
495 |
+
$value = wp_kses_post( $value );
|
496 |
+
} else {
|
497 |
+
$value = wp_kses( $value, array() );
|
498 |
+
}
|
499 |
+
|
500 |
+
if ( 'content' == $field->get_association() ) {
|
501 |
+
if ( $field->data( 'allow_filters' ) ) {
|
502 |
+
$value = apply_filters( 'the_content', $value );
|
503 |
+
} elseif ( $field->data( 'allow_shortcodes' ) ) {
|
504 |
+
$value = do_shortcode( nl2br( $value ) );
|
505 |
+
} else {
|
506 |
+
$value = nl2br( $value );
|
507 |
+
}
|
508 |
+
} else {
|
509 |
+
$value = nl2br( $value );
|
510 |
+
}
|
511 |
+
|
512 |
+
return $value;
|
513 |
+
}
|
514 |
+
|
515 |
+
}
|
516 |
+
|
517 |
+
class WPBDP_FieldTypes_RadioButton extends WPBDP_Form_Field_Type {
|
518 |
+
|
519 |
+
public function __construct() {
|
520 |
+
parent::__construct( _x('Radio button', 'form-fields api', 'WPBDM') );
|
521 |
+
}
|
522 |
+
|
523 |
+
public function get_id() {
|
524 |
+
return 'radio';
|
525 |
+
}
|
526 |
+
|
527 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
528 |
+
$options = $field->data( 'options' ) ? $field->data( 'options' ) : array();
|
529 |
+
|
530 |
+
if ( $field->get_association() == 'tags' && !$options ) {
|
531 |
+
$tags = get_terms( WPBDP_TAGS_TAX, array( 'hide_empty' => false, 'fields' => 'names' ) );
|
532 |
+
$options = array_combine( $tags, $tags );
|
533 |
+
} elseif ( $field->get_association() == 'category' ) {
|
534 |
+
$html = wp_list_categories( array(
|
535 |
+
'taxonomy' => WPBDP_CATEGORY_TAX,
|
536 |
+
'orderby' => wpbdp_get_option( 'categories-order-by' ),
|
537 |
+
'order' => wpbdp_get_option( 'categories-sort' ),
|
538 |
+
'hide_empty' => 0,
|
539 |
+
'echo' => 0,
|
540 |
+
'depth' => 0,
|
541 |
+
'walker' => new CategoryFormInputWalker( 'radio', $value, $field ),
|
542 |
+
'show_option_none' => '',
|
543 |
+
'title_li' => '',
|
544 |
+
) );
|
545 |
+
|
546 |
+
return $html;
|
547 |
+
}
|
548 |
+
|
549 |
+
$html = '';
|
550 |
+
$i = 1;
|
551 |
+
foreach ( $options as $option => $label ) {
|
552 |
+
$css_classes = array();
|
553 |
+
$css_classes[] = 'wpbdp-inner-radio';
|
554 |
+
$css_classes[] = 'wpbdp-inner-radio-' . $i;
|
555 |
+
$css_classes[] = 'wpbdp-inner-radio-' . WPBDP_Form_Field_Type::normalize_name( $label );
|
556 |
+
|
557 |
+
$html .= sprintf( '<span class="%s" style="padding-right: 10px;"><input type="radio" name="%s" class="%s" value="%s" %s />%s</span>',
|
558 |
+
implode( ' ', $css_classes ),
|
559 |
+
'listingfields[' . $field->get_id() . ']',
|
560 |
+
$field->is_required() ? 'inradio required' : 'inradio',
|
561 |
+
$option,
|
562 |
+
$value == $option ? 'checked="checked"' : '',
|
563 |
+
esc_attr( $label )
|
564 |
+
);
|
565 |
+
$i++;
|
566 |
+
}
|
567 |
+
|
568 |
+
return $html;
|
569 |
+
}
|
570 |
+
|
571 |
+
public function get_supported_associations() {
|
572 |
+
return array( 'category', 'tags', 'meta' );
|
573 |
+
}
|
574 |
+
|
575 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
576 |
+
if ( $association != 'meta' && $association != 'tags' )
|
577 |
+
return '';
|
578 |
+
|
579 |
+
$label = _x( 'Field Options (for select lists, radio buttons and checkboxes).', 'form-fields admin', 'WPBDM' ) . '<span class="description">(required)</span>';
|
580 |
+
|
581 |
+
$content = '<span class="description">Comma (,) separated list of options</span><br />';
|
582 |
+
$content .= '<textarea name="field[x_options]" cols="50" rows="2">';
|
583 |
+
|
584 |
+
if ( $field && $field->data( 'options' ) )
|
585 |
+
$content .= implode( ',', $field->data( 'options' ) );
|
586 |
+
$content .= '</textarea>';
|
587 |
+
|
588 |
+
return self::render_admin_settings( array( array( $label, $content ) ) );
|
589 |
+
}
|
590 |
+
|
591 |
+
public function process_field_settings( &$field ) {
|
592 |
+
if ( !array_key_exists( 'x_options', $_POST['field'] ) )
|
593 |
+
return;
|
594 |
+
|
595 |
+
$options = trim( $_POST['field']['x_options'] );
|
596 |
+
|
597 |
+
if ( !$options && $field->get_association() != 'tags' )
|
598 |
+
return new WP_Error( 'wpbdp-invalid-settings', _x( 'Field list of options is required.', 'form-fields admin', 'WPBDM' ) );
|
599 |
+
|
600 |
+
$field->set_data( 'options', !empty( $options ) ? explode( ',', $options ) : array() );
|
601 |
+
}
|
602 |
+
|
603 |
+
public function get_field_value( &$field, $post_id ) {
|
604 |
+
$value = parent::get_field_value( $field, $post_id );
|
605 |
+
return is_array( $value ) ? $value[0] : $value;
|
606 |
+
}
|
607 |
+
|
608 |
+
public function get_field_plain_value( &$field, $post_id ) {
|
609 |
+
$value = $field->value( $post_id );
|
610 |
+
|
611 |
+
if ( $field->get_association() == 'category' || $field->get_association() == 'tags' ) {
|
612 |
+
$term = get_term( is_array( $value ) ? $value[0] : $value,
|
613 |
+
$field->get_association() == 'category' ? WPBDP_CATEGORY_TAX : WPBDP_TAGS_TAX );
|
614 |
+
return esc_attr( $term->name );
|
615 |
+
}
|
616 |
+
|
617 |
+
return strval( $value );
|
618 |
+
}
|
619 |
+
|
620 |
+
|
621 |
+
}
|
622 |
+
|
623 |
+
class WPBDP_FieldTypes_MultiSelect extends WPBDP_FieldTypes_Select {
|
624 |
+
|
625 |
+
public function __construct() {
|
626 |
+
parent::__construct( _x('Multiple select list', 'form-fields api', 'WPBDM') );
|
627 |
+
$this->set_multiple( true );
|
628 |
+
}
|
629 |
+
|
630 |
+
public function get_name() {
|
631 |
+
return _x( 'Multiselect List', 'form-fields api', 'WPBDM' );
|
632 |
+
}
|
633 |
+
|
634 |
+
public function get_id() {
|
635 |
+
return 'multiselect';
|
636 |
+
}
|
637 |
+
|
638 |
+
public function get_supported_associations() {
|
639 |
+
return array( 'category', 'tags', 'meta' );
|
640 |
+
}
|
641 |
+
|
642 |
+
}
|
643 |
+
|
644 |
+
class WPBDP_FieldTypes_Checkbox extends WPBDP_Form_Field_Type {
|
645 |
+
|
646 |
+
public function __construct() {
|
647 |
+
parent::__construct( _x('Checkbox', 'form-fields api', 'WPBDM') );
|
648 |
+
}
|
649 |
+
|
650 |
+
public function get_id() {
|
651 |
+
return 'checkbox';
|
652 |
+
}
|
653 |
+
|
654 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
655 |
+
$options = $field->data( 'options' ) ? $field->data( 'options') : array();
|
656 |
+
|
657 |
+
if ( $field->get_association() == 'tags' && !$options ) {
|
658 |
+
$tags = get_terms( WPBDP_TAGS_TAX, array( 'hide_empty' => false, 'fields' => 'names' ) );
|
659 |
+
$options = array_combine( $tags, $tags );
|
660 |
+
} elseif ( $field->get_association() == 'category' ) {
|
661 |
+
$html = wp_list_categories( array(
|
662 |
+
'taxonomy' => WPBDP_CATEGORY_TAX,
|
663 |
+
'orderby' => wpbdp_get_option( 'categories-order-by' ),
|
664 |
+
'order' => wpbdp_get_option( 'categories-sort' ),
|
665 |
+
'hide_empty' => 0,
|
666 |
+
'echo' => 0,
|
667 |
+
'depth' => 0,
|
668 |
+
'walker' => new CategoryFormInputWalker( 'checkbox', $value, $field ),
|
669 |
+
'show_option_none' => '',
|
670 |
+
'title_li' => '',
|
671 |
+
) );
|
672 |
+
|
673 |
+
return $html;
|
674 |
+
}
|
675 |
+
|
676 |
+
$html = '';
|
677 |
+
$i = 1;
|
678 |
+
foreach ( $options as $option_key => $label ) {
|
679 |
+
$css_classes = array();
|
680 |
+
$css_classes[] = 'wpbdp-inner-checkbox';
|
681 |
+
$css_classes[] = 'wpbdp-inner-checkbox-' . $i;
|
682 |
+
$css_classes[] = 'wpbdp-inner-checkbox-' . WPBDP_Form_Field_Type::normalize_name( $label );
|
683 |
+
|
684 |
+
$html .= sprintf( '<div class="wpbdmcheckboxclass %s"><input type="checkbox" class="%s" name="%s" value="%s" %s/> %s</div>',
|
685 |
+
implode( ' ', $css_classes ),
|
686 |
+
$field->is_required() ? 'required' : '',
|
687 |
+
'listingfields[' . $field->get_id() . '][]',
|
688 |
+
$option_key,
|
689 |
+
in_array( $option_key, is_array( $value ) ? $value : array( $value ) ) ? 'checked="checked"' : '',
|
690 |
+
esc_attr( $label ) );
|
691 |
+
|
692 |
+
$i++;
|
693 |
+
}
|
694 |
+
|
695 |
+
$html .= '<div style="clear:both;"></div>';
|
696 |
+
|
697 |
+
return $html;
|
698 |
+
}
|
699 |
+
|
700 |
+
public function get_supported_associations() {
|
701 |
+
return array( 'category', 'tags', 'meta' );
|
702 |
+
}
|
703 |
+
|
704 |
+
public function render_field_settings( &$field=null, $association=null ) {
|
705 |
+
if ( $association != 'meta' && $association != 'tags' )
|
706 |
+
return '';
|
707 |
+
|
708 |
+
$settings = array();
|
709 |
+
|
710 |
+
$settings['options'][] = _x( 'Field Options (for select lists, radio buttons and checkboxes).', 'form-fields admin', 'WPBDM' ) . '<span class="description">(required)</span>';
|
711 |
+
|
712 |
+
$content = '<span class="description">Comma (,) separated list of options</span><br />';
|
713 |
+
$content .= '<textarea name="field[x_options]" cols="50" rows="2">';
|
714 |
+
|
715 |
+
if ( $field && $field->data( 'options' ) )
|
716 |
+
$content .= implode( ',', $field->data( 'options' ) );
|
717 |
+
$content .= '</textarea>';
|
718 |
+
|
719 |
+
$settings['options'][] = $content;
|
720 |
+
|
721 |
+
return self::render_admin_settings( $settings );
|
722 |
+
}
|
723 |
+
|
724 |
+
public function process_field_settings( &$field ) {
|
725 |
+
if ( !array_key_exists( 'x_options', $_POST['field'] ) )
|
726 |
+
return;
|
727 |
+
|
728 |
+
$options = trim( $_POST['field']['x_options'] );
|
729 |
+
|
730 |
+
if ( !$options && $field->get_association() != 'tags' )
|
731 |
+
return new WP_Error( 'wpbdp-invalid-settings', _x( 'Field list of options is required.', 'form-fields admin', 'WPBDM' ) );
|
732 |
+
|
733 |
+
$field->set_data( 'options', !empty( $options ) ? explode( ',', $options ) : array() );
|
734 |
+
}
|
735 |
+
|
736 |
+
public function store_field_value( &$field, $post_id, $value ) {
|
737 |
+
if ( $field->get_association() == 'meta' ) {
|
738 |
+
$value = implode( "\t", is_array( $value ) ? $value : array( $value ) );
|
739 |
+
}
|
740 |
+
|
741 |
+
parent::store_field_value( $field, $post_id, $value );
|
742 |
+
}
|
743 |
+
|
744 |
+
public function get_field_value( &$field, $post_id ) {
|
745 |
+
$value = parent::get_field_value( $field, $post_id );
|
746 |
+
$value = empty( $value ) ? array() : $value;
|
747 |
+
|
748 |
+
if ( is_string( $value ) )
|
749 |
+
return explode( "\t", $value );
|
750 |
+
|
751 |
+
return $value;
|
752 |
+
}
|
753 |
+
|
754 |
+
public function get_field_html_value( &$field, $post_id ) {
|
755 |
+
if ( $field->get_association() == 'meta' ) {
|
756 |
+
return esc_attr( implode( ', ', $field->value( $post_id ) ) );
|
757 |
+
}
|
758 |
+
|
759 |
+
return parent::get_field_html_value( $field, $post_id );
|
760 |
+
}
|
761 |
+
|
762 |
+
public function get_field_plain_value( &$field, $post_id ) {
|
763 |
+
$value = $field->value( $post_id );
|
764 |
+
|
765 |
+
if ( $field->get_association() == 'category' || $field->get_association() == 'tags' ) {
|
766 |
+
$term_names = get_terms( $field->get_association() == 'category' ? WPBDP_CATEGORY_TAX : WPBDP_TAGS_TAX,
|
767 |
+
array( 'include' => $value, 'hide_empty' => 0, 'fields' => 'names' ) );
|
768 |
+
|
769 |
+
return join( ', ', $term_names );
|
770 |
+
} elseif ( $field->get_association() == 'meta' ) {
|
771 |
+
return esc_attr( implode( ', ', $value ) );
|
772 |
+
}
|
773 |
+
|
774 |
+
return strval( $value );
|
775 |
+
}
|
776 |
+
|
777 |
+
/**
|
778 |
+
* @since 3.4.1
|
779 |
+
*/
|
780 |
+
public function get_field_csv_value( &$field, $post_id ) {
|
781 |
+
if ( 'meta' != $field->get_association() )
|
782 |
+
return $this->get_field_plain_value( $field, $post_id );
|
783 |
+
|
784 |
+
$value = $field->value( $post_id );
|
785 |
+
return esc_attr( implode( ',', $value ) );
|
786 |
+
}
|
787 |
+
|
788 |
+
/**
|
789 |
+
* @since 3.4.1
|
790 |
+
*/
|
791 |
+
public function convert_csv_input( &$field, $input = '' ) {
|
792 |
+
if ( 'meta' != $field->get_association() )
|
793 |
+
return $this->convert_input( $field, $input );
|
794 |
+
|
795 |
+
if ( ! $input )
|
796 |
+
return array();
|
797 |
+
|
798 |
+
return explode( ',', $input );
|
799 |
+
}
|
800 |
+
}
|
801 |
+
|
802 |
+
class WPBDP_FieldTypes_Twitter extends WPBDP_Form_Field_Type {
|
803 |
+
|
804 |
+
public function __construct() {
|
805 |
+
parent::__construct( _x('Social Site (Twitter handle)', 'form-fields api', 'WPBDM') );
|
806 |
+
}
|
807 |
+
|
808 |
+
public function get_id() {
|
809 |
+
return 'social-twitter';
|
810 |
+
}
|
811 |
+
|
812 |
+
public function setup_field( &$field ) {
|
813 |
+
$field->add_display_flag( 'social' );
|
814 |
+
}
|
815 |
+
|
816 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
817 |
+
// twitter fields are rendered as normal textfields
|
818 |
+
global $wpbdp;
|
819 |
+
return $wpbdp->formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value, $context, $extra );
|
820 |
+
}
|
821 |
+
|
822 |
+
public function get_supported_associations() {
|
823 |
+
return array( 'meta' );
|
824 |
+
}
|
825 |
+
|
826 |
+
public function get_field_value( &$field, $post_id ) {
|
827 |
+
$value = parent::get_field_value( $field, $post_id );
|
828 |
+
|
829 |
+
$value = str_ireplace( array('http://twitter.com/', 'https://twitter.com/', 'http://www.twitter.com/', 'https://www.twitter.com/'), '', $value );
|
830 |
+
$value = rtrim( $value, '/' );
|
831 |
+
$value = ltrim( $value, ' @' );
|
832 |
+
|
833 |
+
return $value;
|
834 |
+
}
|
835 |
+
|
836 |
+
public function get_field_html_value( &$field, $post_id ) {
|
837 |
+
$value = $field->value( $post_id );
|
838 |
+
|
839 |
+
$html = '';
|
840 |
+
$html .= '<div class="social-field twitter">';
|
841 |
+
$html .= sprintf('<a href="https://twitter.com/%s" class="twitter-follow-button" data-show-count="false" data-lang="%s">Follow @%s</a>',
|
842 |
+
$value, substr( get_bloginfo( 'language' ), 0, 2 ), $value);
|
843 |
+
$html .= '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
|
844 |
+
$html .= '</div>';
|
845 |
+
|
846 |
+
return $html;
|
847 |
+
}
|
848 |
+
|
849 |
+
}
|
850 |
+
|
851 |
+
class WPBDP_FieldTypes_Facebook extends WPBDP_Form_Field_Type {
|
852 |
+
|
853 |
+
public function __construct() {
|
854 |
+
parent::__construct( _x('Social Site (Facebook page)', 'form-fields api', 'WPBDM') );
|
855 |
+
}
|
856 |
+
|
857 |
+
public function get_id() {
|
858 |
+
return 'social-facebook';
|
859 |
+
}
|
860 |
+
|
861 |
+
public function setup_field( &$field ) {
|
862 |
+
$field->add_display_flag( 'social' );
|
863 |
+
}
|
864 |
+
|
865 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
866 |
+
// facebook fields are rendered as normal textfields
|
867 |
+
global $wpbdp;
|
868 |
+
return $wpbdp->formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value, $context, $extra );
|
869 |
+
}
|
870 |
+
|
871 |
+
public function get_supported_associations() {
|
872 |
+
return array( 'meta' );
|
873 |
+
}
|
874 |
+
|
875 |
+
public function get_field_html_value( &$field, $post_id ) {
|
876 |
+
$value = $field->value( $post_id );
|
877 |
+
|
878 |
+
$html = '';
|
879 |
+
$html .= '<div class="social-field facebook">';
|
880 |
+
$html .= '<div id="fb-root"></div>';
|
881 |
+
$html .= '<script>(function(d, s, id) {
|
882 |
+
var js, fjs = d.getElementsByTagName(s)[0];
|
883 |
+
if (d.getElementById(id)) return;
|
884 |
+
js = d.createElement(s); js.id = id;
|
885 |
+
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
|
886 |
+
fjs.parentNode.insertBefore(js, fjs);
|
887 |
+
}(document, \'script\', \'facebook-jssdk\'));</script>';
|
888 |
+
|
889 |
+
// data-layout can be 'box_count', 'standard' or 'button_count'
|
890 |
+
// ref: https://developers.facebook.com/docs/reference/plugins/like/
|
891 |
+
$html .= sprintf( '<div class="fb-like" data-href="%s" data-send="false" data-width="200" data-layout="button_count" data-show-faces="false"></div>', $value );
|
892 |
+
$html .= '</div>';
|
893 |
+
|
894 |
+
return $html;
|
895 |
+
}
|
896 |
+
|
897 |
+
}
|
898 |
+
|
899 |
+
class WPBDP_FieldTypes_LinkedIn extends WPBDP_Form_Field_Type {
|
900 |
+
|
901 |
+
public function __construct() {
|
902 |
+
parent::__construct( _x('Social Site (LinkedIn profile)', 'form-fields api', 'WPBDM') );
|
903 |
+
}
|
904 |
+
|
905 |
+
public function get_id() {
|
906 |
+
return 'social-linkedin';
|
907 |
+
}
|
908 |
+
|
909 |
+
public function setup_field( &$field ) {
|
910 |
+
$field->add_display_flag( 'social' );
|
911 |
+
}
|
912 |
+
|
913 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
914 |
+
// LinkedIn fields are rendered as normal textfields
|
915 |
+
global $wpbdp;
|
916 |
+
return $wpbdp->formfields->get_field_type( 'textfield' )->render_field_inner( $field, $value, $context, $extra );
|
917 |
+
}
|
918 |
+
|
919 |
+
public function get_supported_associations() {
|
920 |
+
return array( 'meta' );
|
921 |
+
}
|
922 |
+
|
923 |
+
public function get_field_html_value( &$field, $post_id ) {
|
924 |
+
$value = $field->value( $post_id );
|
925 |
+
|
926 |
+
static $js_loaded = false;
|
927 |
+
|
928 |
+
$html = '';
|
929 |
+
if ( $value ) {
|
930 |
+
if ( !$js_loaded ) {
|
931 |
+
$html .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>';
|
932 |
+
$js_loaded = true;
|
933 |
+
}
|
934 |
+
|
935 |
+
$html .= '<script type="IN/FollowCompany" data-id="' . intval( $value ) . '" data-counter="none"></script>';
|
936 |
+
}
|
937 |
+
|
938 |
+
return $html;
|
939 |
+
}
|
940 |
+
|
941 |
+
}
|
942 |
+
|
943 |
+
|
944 |
+
class WPBDP_FieldTypes_Image extends WPBDP_Form_Field_Type {
|
945 |
+
|
946 |
+
public function __construct() {
|
947 |
+
parent::__construct( _x( 'Image (file upload)', 'form-fields api', 'WPBDM' ) );
|
948 |
+
}
|
949 |
+
|
950 |
+
public function get_id() {
|
951 |
+
return 'image';
|
952 |
+
}
|
953 |
+
|
954 |
+
public function get_supported_associations() {
|
955 |
+
return array( 'meta' );
|
956 |
+
}
|
957 |
+
|
958 |
+
public function setup_field( &$field ) {
|
959 |
+
$field->remove_display_flag( 'search' ); // image fields are not searchable
|
960 |
+
}
|
961 |
+
|
962 |
+
public function render_field_inner( &$field, $value, $context, &$extra=null ) {
|
963 |
+
if ( $context == 'search' )
|
964 |
+
return '';
|
965 |
+
|
966 |
+
$html = '';
|
967 |
+
$html .= sprintf( '<input type="hidden" name="listingfields[%d]" value="%s" />',
|
968 |
+
$field->get_id(),
|
969 |
+
$value
|
970 |
+
);
|
971 |
+
|
972 |
+
$html .= '<div class="preview">';
|
973 |
+
if ($value)
|
974 |
+
$html .= wp_get_attachment_image( $value, 'thumb', false );
|
975 |
+
|
976 |
+
$html .= sprintf( '<a href="http://google.com" class="delete" onclick="return WPBDP.fileUpload.deleteUpload(%d);" style="%s">%s</a>',
|
977 |
+
$field->get_id(),
|
978 |
+
!$value ? 'display: none;' : '',
|
979 |
+
_x( 'Remove', 'form-fields-api', 'WPBDM' )
|
980 |
+
);
|
981 |
+
|
982 |
+
$html .= '</div>';
|
983 |
+
|
984 |
+
$ajax_url = add_query_arg( array( 'action' => 'wpbdp-file-field-upload',
|
985 |
+
'field_id' => $field->get_id(),
|
986 |
+
'element' => 'listingfields[' . $field->get_id() . ']' ),
|
987 |
+
admin_url( 'admin-ajax.php' ) );
|
988 |
+
|
989 |
+
$html .= '<div class="wpbdp-upload-widget">';
|
990 |
+
$html .= sprintf( '<iframe class="wpbdp-upload-iframe" name="upload-iframe-%d" id="wpbdp-upload-iframe-%d" src="%s" scrolling="no" seamless="seamless" border="0" frameborder="0"></iframe>',
|
991 |
+
$field->get_id(),
|
992 |
+
$field->get_id(),
|
993 |
+
$ajax_url
|
994 |
+
);
|
995 |
+
$html .= '</div>';
|
996 |
+
|
997 |
+
return $html;
|
998 |
+
}
|
999 |
+
|
1000 |
+
public function get_field_html_value( &$field, $post_id ) {
|
1001 |
+
$value = $field->value( $post_id );
|
1002 |
+
|
1003 |
+
return '<br />' . wp_get_attachment_image( $value, 'thumb', false );
|
1004 |
+
}
|
1005 |
+
|
1006 |
+
}
|
1007 |
+
|
1008 |
+
// Custom category walker (used when rendering category fields using radios or checkboxes)
|
1009 |
+
class CategoryFormInputWalker extends Walker {
|
1010 |
+
var $tree_type = 'category';
|
1011 |
+
var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
|
1012 |
+
|
1013 |
+
private $input_type;
|
1014 |
+
private $selected;
|
1015 |
+
private $field;
|
1016 |
+
|
1017 |
+
public function __construct( $input_type='radio', $selected=null, &$field=null ) {
|
1018 |
+
$this->input_type = $input_type;
|
1019 |
+
$this->selected = $selected;
|
1020 |
+
$this->field = $field;
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
|
1024 |
+
switch ( $this->input_type ) {
|
1025 |
+
case 'checkbox':
|
1026 |
+
$output .= '<div class="wpbdmcheckboxclass">';
|
1027 |
+
$output .= sprintf( '<input type="checkbox" class="%s" name="%s" value="%s" %s style="margin-left: %dpx;" />%s',
|
1028 |
+
$this->field->is_required() ? 'required' : '',
|
1029 |
+
'listingfields[' . $this->field->get_id() . '][]',
|
1030 |
+
$category->term_id,
|
1031 |
+
in_array( $category->term_id, is_array( $this->selected ) ? $this->selected : array( $this->selected ) ) ? 'checked="checked"' : '',
|
1032 |
+
$depth * 10,
|
1033 |
+
esc_attr( $category->name )
|
1034 |
+
);
|
1035 |
+
$output .= '</div>';
|
1036 |
+
break;
|
1037 |
+
case 'radio':
|
1038 |
+
default:
|
1039 |
+
$output .= sprintf( '<input type="radio" name="%s" class="%s" value="%s" %s style="margin-left: %dpx;"> %s<br />',
|
1040 |
+
'listingfields[' . $this->field->get_id() . ']',
|
1041 |
+
$this->field->is_required() ? 'inradio required' : 'inradio',
|
1042 |
+
$category->term_id,
|
1043 |
+
$this->selected == $category->term_id ? 'checked="checked"' : '',
|
1044 |
+
$depth * 10,
|
1045 |
+
esc_attr( $category->name )
|
1046 |
+
);
|
1047 |
+
break;
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
}
|
1051 |
+
}
|
core/form-fields.php
ADDED
@@ -0,0 +1,550 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Form fields API.
|
4 |
+
*/
|
5 |
+
|
6 |
+
if (!class_exists('WPBDP_FormFields')) {
|
7 |
+
|
8 |
+
require_once( WPBDP_PATH . 'core/class-form-field.php' );
|
9 |
+
require_once( WPBDP_PATH . 'core/form-fields-types.php' );
|
10 |
+
|
11 |
+
class WPBDP_FormFields {
|
12 |
+
|
13 |
+
private $associations = array();
|
14 |
+
private $association_flags = array();
|
15 |
+
private $association_field_types = array();
|
16 |
+
|
17 |
+
private $field_types = array();
|
18 |
+
|
19 |
+
private static $instance = null;
|
20 |
+
|
21 |
+
public static function instance() {
|
22 |
+
if (is_null(self::$instance)) {
|
23 |
+
self::$instance = new self;
|
24 |
+
}
|
25 |
+
|
26 |
+
return self::$instance;
|
27 |
+
}
|
28 |
+
|
29 |
+
private function __construct() {
|
30 |
+
// register core associations
|
31 |
+
$this->register_association( 'title', _x( 'Post Title', 'form-fields api', 'WPBDM' ), array( 'required', 'unique' ) );
|
32 |
+
$this->register_association( 'content', _x( 'Post Content', 'form-fields api', 'WPBDM' ), array( 'required', 'unique' ) );
|
33 |
+
$this->register_association( 'excerpt', _x( 'Post Excerpt', 'form-fields api', 'WPBDM' ), array( 'unique' ) );
|
34 |
+
$this->register_association( 'category', _x( 'Post Category', 'form-fields api', 'WPBDM' ), array( 'required', 'unique' ) );
|
35 |
+
$this->register_association( 'tags', _x( 'Post Tags', 'form-fields api', 'WPBDM' ), array( 'unique' ) );
|
36 |
+
$this->register_association( 'meta', _x( 'Post Metadata', 'form-fields api', 'WPBDM' ) );
|
37 |
+
|
38 |
+
$this->register_association( 'custom', _x('Custom', 'form-fields api', 'WPBDM'), array( 'private' ) );
|
39 |
+
|
40 |
+
// register core field types
|
41 |
+
$this->register_field_type( 'WPBDP_FieldTypes_TextField', 'textfield' );
|
42 |
+
$this->register_field_type( 'WPBDP_FieldTypes_Select', 'select' );
|
43 |
+
$this->register_field_type( 'WPBDP_FieldTypes_URL', 'url' );
|
44 |
+
$this->register_field_type( 'WPBDP_FieldTypes_TextArea', 'textarea' );
|
45 |
+
$this->register_field_type( 'WPBDP_FieldTypes_RadioButton', 'radio' );
|
46 |
+
$this->register_field_type( 'WPBDP_FieldTypes_MultiSelect', 'multiselect' );
|
47 |
+
$this->register_field_type( 'WPBDP_FieldTypes_Checkbox', 'checkbox' );
|
48 |
+
$this->register_field_type( 'WPBDP_FieldTypes_Twitter', 'social-twitter' );
|
49 |
+
$this->register_field_type( 'WPBDP_FieldTypes_Facebook', 'social-facebook' );
|
50 |
+
$this->register_field_type( 'WPBDP_FieldTypes_LinkedIn', 'social-linkedin' );
|
51 |
+
$this->register_field_type( 'WPBDP_FieldTypes_Image', 'image' );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Registers a new association within the form fields API.
|
56 |
+
* @param string $association association id
|
57 |
+
* @param string $name human-readable name
|
58 |
+
* @param array $flags association flags
|
59 |
+
*/
|
60 |
+
public function register_association( $association, $name='', $flags=array() ) {
|
61 |
+
if ( isset( $this->associations[$association] ) )
|
62 |
+
return false;
|
63 |
+
|
64 |
+
$this->associations[ $association ] = $name ? $name : $association;
|
65 |
+
$this->association_flags[ $association ] = is_array( $flags ) ? $flags : array( strval( $flags ) );
|
66 |
+
|
67 |
+
if ( !isset( $this->association_field_types[ $association ] ) )
|
68 |
+
$this->association_field_types[ $association ] = array();
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Returns the known form field associations.
|
73 |
+
* @return array associative array with key/name pairs
|
74 |
+
*/
|
75 |
+
public function &get_associations() {
|
76 |
+
return $this->associations;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function get_association_field_types( $association=null ) {
|
80 |
+
if ( $association ) {
|
81 |
+
if ( in_array( $association, array_keys( $this->associations ), true ) ) {
|
82 |
+
return $this->association_field_types[ $association ];
|
83 |
+
} else {
|
84 |
+
return null;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
return $this->association_field_types;
|
89 |
+
}
|
90 |
+
|
91 |
+
public function get_association_flags( $association ) {
|
92 |
+
if ( array_key_exists( $association, $this->associations ) )
|
93 |
+
return $this->association_flags[ $association ];
|
94 |
+
|
95 |
+
return array();
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Returns associations marked with the given flags.
|
100 |
+
* @param string|array $flags flags to be checked
|
101 |
+
* @param boolean $any if True associations marked with any (and not all) of the flags will also be returned
|
102 |
+
* @return array
|
103 |
+
*/
|
104 |
+
public function &get_associations_with_flag( $flags, $any=false ) {
|
105 |
+
if ( is_string( $flags ) )
|
106 |
+
$flags = array( $flags );
|
107 |
+
|
108 |
+
$res = array();
|
109 |
+
|
110 |
+
foreach ( $this->association_flags as $association => $association_flags ) {
|
111 |
+
$intersection = array_intersect( $flags, $association_flags );
|
112 |
+
|
113 |
+
if ( ( $any && ( count( $intersection ) > 0 ) ) || ( !$any && ( count( $intersection ) == count( $flags ) ) ) )
|
114 |
+
$res[] = $association;
|
115 |
+
}
|
116 |
+
|
117 |
+
return $res;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Get associations with their flags at the same time.
|
122 |
+
*
|
123 |
+
* @since 3.4
|
124 |
+
*/
|
125 |
+
public function &get_associations_with_flags() {
|
126 |
+
$res = array();
|
127 |
+
|
128 |
+
foreach ( $this->associations as $assoc_id => $assoc_label ) {
|
129 |
+
$flags = $this->association_flags[ $assoc_id ];
|
130 |
+
$res[ $assoc_id ] = (object) array( 'id' => $assoc_id, 'label' => $assoc_label, 'flags' => $flags );
|
131 |
+
}
|
132 |
+
|
133 |
+
return $res;
|
134 |
+
}
|
135 |
+
|
136 |
+
public function &get_required_field_associations() {
|
137 |
+
return $this->get_associations_with_flag( 'required' );
|
138 |
+
}
|
139 |
+
|
140 |
+
public function &get_field_type( $field_type ) {
|
141 |
+
$field_type_obj = wpbdp_getv( $this->field_types, $field_type, null );
|
142 |
+
return $field_type_obj;
|
143 |
+
}
|
144 |
+
|
145 |
+
public function &get_field_types() {
|
146 |
+
return $this->field_types;
|
147 |
+
}
|
148 |
+
|
149 |
+
public function get_validators() {
|
150 |
+
$validators = WPBDP_FieldValidation::instance()->get_validators();
|
151 |
+
return $validators;
|
152 |
+
}
|
153 |
+
|
154 |
+
public function register_field_type( $field_type_class, $alias=null ) {
|
155 |
+
$field_type = new $field_type_class();
|
156 |
+
|
157 |
+
$this->field_types[ $alias ? $alias : $field_type_class ] = $field_type;
|
158 |
+
|
159 |
+
foreach ( $field_type->get_supported_associations() as $association ) {
|
160 |
+
$this->association_field_types[ $association ] = array_merge( isset( $this->association_field_types[ $association ] ) ? $this->association_field_types[ $association ] : array(), array( $alias ? $alias : $field_type_class ) );
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
public function &get_field( $id=0 ) {
|
165 |
+
$field = WPBDP_FormField::get( $id );
|
166 |
+
return $field;
|
167 |
+
}
|
168 |
+
|
169 |
+
public function &get_fields( $lightweight = false ) {
|
170 |
+
global $wpdb;
|
171 |
+
|
172 |
+
if ( $lightweight ) {
|
173 |
+
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpbdp_form_fields ORDER BY weight DESC" );
|
174 |
+
return $results;
|
175 |
+
}
|
176 |
+
|
177 |
+
$res = array();
|
178 |
+
$field_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->prefix}wpbdp_form_fields ORDER BY weight DESC" );
|
179 |
+
|
180 |
+
foreach ( $field_ids as $field_id ) {
|
181 |
+
if ( $field = WPBDP_FormField::get( $field_id ) )
|
182 |
+
$res[] = $field;
|
183 |
+
}
|
184 |
+
|
185 |
+
return $res;
|
186 |
+
}
|
187 |
+
|
188 |
+
public function &find_fields( $args=array(), $one=false ) {
|
189 |
+
global $wpdb;
|
190 |
+
$res = array();
|
191 |
+
|
192 |
+
$args = wp_parse_args( $args, array(
|
193 |
+
'association' => null,
|
194 |
+
'field_type' => null,
|
195 |
+
'validators' => null,
|
196 |
+
'display_flags' => null,
|
197 |
+
'unique' => false
|
198 |
+
) );
|
199 |
+
|
200 |
+
if ( $one == true )
|
201 |
+
$args['unique'] = true;
|
202 |
+
|
203 |
+
extract( $args );
|
204 |
+
|
205 |
+
$validators = $validators ? ( !is_array( $validators ) ? array( $validators ) : $validators ) : array();
|
206 |
+
$display_flags = $display_flags ? ( !is_array( $display_flags ) ? array( $display_flags ) : $display_flags ) : array();
|
207 |
+
|
208 |
+
$where = '';
|
209 |
+
if ( $args['association'] ) {
|
210 |
+
$associations_in = array();
|
211 |
+
$associations_not_in = array();
|
212 |
+
|
213 |
+
$association = !is_array( $association) ? array( $association ) : $association;
|
214 |
+
|
215 |
+
foreach ( $association as &$assoc ) {
|
216 |
+
if ( wpbdp_starts_with( $assoc, '-' ) ) {
|
217 |
+
$associations_not_in[] = substr( $assoc, 1 );
|
218 |
+
} else {
|
219 |
+
$associations_in[] = $assoc;
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
if ( $associations_in ) {
|
224 |
+
$where .= ' AND ( association IN ( \'' . implode( '\',\'', $associations_in) . '\' ) ) ';
|
225 |
+
}
|
226 |
+
|
227 |
+
if ( $associations_not_in ) {
|
228 |
+
$where .= ' AND ( association NOT IN ( \'' . implode( '\',\'', $associations_not_in) . '\' ) ) ';
|
229 |
+
}
|
230 |
+
|
231 |
+
// $where .= $wpdb->prepare( " AND ( association = %s ) ", $args['association'] );
|
232 |
+
}
|
233 |
+
|
234 |
+
if ( $args['field_type'] ) {
|
235 |
+
$field_types_in = array();
|
236 |
+
$field_types_not_in = array();
|
237 |
+
|
238 |
+
$field_type = ! is_array( $field_type ) ? array( $field_type ) : $field_type;
|
239 |
+
|
240 |
+
foreach ( $field_type as $f ) {
|
241 |
+
if ( wpbdp_starts_with( $f, '-' ) ) {
|
242 |
+
$field_types_not_in[] = substr( $f, 1 );
|
243 |
+
} else {
|
244 |
+
$field_types_in[] = $f;
|
245 |
+
}
|
246 |
+
}
|
247 |
+
|
248 |
+
if ( $field_types_in )
|
249 |
+
$where .= ' AND ( field_type IN ( \'' . implode( '\',\'', $field_types_in ) . '\' ) ) ';
|
250 |
+
|
251 |
+
if ( $field_types_not_in )
|
252 |
+
$where .= ' AND ( field_type NOT IN ( \'' . implode( '\',\'', $field_types_not_in ) . '\' ) ) ';
|
253 |
+
}
|
254 |
+
|
255 |
+
foreach ( $display_flags as $f ) {
|
256 |
+
if ( substr($f, 0, 1) == '-' )
|
257 |
+
$where .= $wpdb->prepare( " AND ( display_flags IS NULL OR display_flags NOT LIKE '%%%s%%' )", substr( $f, 1 ) );
|
258 |
+
else
|
259 |
+
$where .= $wpdb->prepare( " AND ( display_flags LIKE '%%%s%%' )", $f );
|
260 |
+
}
|
261 |
+
|
262 |
+
foreach ( $validators as $v ) {
|
263 |
+
if ( substr($v, 0, 1) == '-' )
|
264 |
+
$where .= $wpdb->prepare( " AND ( validators IS NULL OR validators NOT LIKE '%%%s%%' )", substr( $v, 1 ) );
|
265 |
+
else
|
266 |
+
$where .= $wpdb->prepare( " AND ( validators LIKE '%%%s%%' )", $v );
|
267 |
+
}
|
268 |
+
|
269 |
+
if ( $where )
|
270 |
+
$sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields WHERE 1=1 {$where} ORDER BY weight DESC";
|
271 |
+
else
|
272 |
+
$sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields ORDER BY weight DESC";
|
273 |
+
|
274 |
+
$ids = $wpdb->get_col( $sql );
|
275 |
+
|
276 |
+
foreach ( $ids as $id ) {
|
277 |
+
if ( $field = WPBDP_FormField::get( $id ) )
|
278 |
+
$res[] = $field;
|
279 |
+
}
|
280 |
+
|
281 |
+
$res = $unique ? ( $res ? $res[0] : null ) : $res;
|
282 |
+
|
283 |
+
return $res;
|
284 |
+
}
|
285 |
+
|
286 |
+
public function get_missing_required_fields() {
|
287 |
+
global $wpdb;
|
288 |
+
|
289 |
+
$missing = $this->get_required_field_associations();
|
290 |
+
|
291 |
+
$sql_in = '(\'' . implode( '\',\'', $missing ) . '\')';
|
292 |
+
$res = $wpdb->get_col( "SELECT association FROM {$wpdb->prefix}wpbdp_form_fields WHERE association IN {$sql_in} GROUP BY association" );
|
293 |
+
|
294 |
+
return array_diff( $missing, $res );
|
295 |
+
}
|
296 |
+
|
297 |
+
public function create_default_fields( $identifiers=array() ) {
|
298 |
+
$default_fields = array(
|
299 |
+
'title' => array( 'label' => __('Business Name', 'WPBDM'), 'field_type' => 'textfield', 'association' => 'title', 'weight' => 9,
|
300 |
+
'validators' => array( 'required' ), 'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
301 |
+
'category' => array( 'label' => __('Business Genre', 'WPBDM'), 'field_type' => 'select', 'association' => 'category', 'weight' => 8,
|
302 |
+
'validators' => array( 'required' ), 'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
303 |
+
'excerpt' => array( 'label' => __('Short Business Description', 'WPBDM'), 'field_type' => 'textarea', 'association' => 'excerpt', 'weight' => 7,
|
304 |
+
'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
305 |
+
'content' => array( 'label' => __("Long Business Description","WPBDM"), 'field_type' => 'textarea', 'association' => 'content', 'weight' => 6,
|
306 |
+
'validators' => array( 'required' ), 'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
307 |
+
'meta0' => array( 'label' => __("Business Website Address","WPBDM"), 'field_type' => 'url', 'association' => 'meta', 'weight' => 5,
|
308 |
+
'validators' => array( 'url' ), 'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
309 |
+
'meta1' => array( 'label' => __("Business Phone Number","WPBDM"), 'field_type' => 'textfield', 'association' => 'meta', 'weight' => 4,
|
310 |
+
'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
311 |
+
'meta2' => array( 'label' => __("Business Fax","WPBDM"), 'field_type' => 'textfield', 'association' => 'meta', 'weight' => 3,
|
312 |
+
'display_flags' => array( 'excerpt', 'listing', 'search' ) ),
|
313 |
+
'meta3' => array( 'label' => __("Business Contact Email","WPBDM"), 'field_type' => 'textfield', 'association' => 'meta', 'weight' => 2,
|
314 |
+
'validators' => array( 'email', 'required' ), 'display_flags' => array( 'excerpt', 'listing' ) ),
|
315 |
+
'meta4' => array( 'label' => __("Business Tags","WPBDM"), 'field_type' => 'textfield', 'association' => 'tags', 'weight' => 1,
|
316 |
+
'display_flags' => array( 'excerpt', 'listing', 'search' ) )
|
317 |
+
);
|
318 |
+
|
319 |
+
$fields_to_create = $identifiers ? array_intersect_key( $default_fields, array_flip ( $identifiers ) ) : $default_fields;
|
320 |
+
|
321 |
+
foreach ( $fields_to_create as &$f) {
|
322 |
+
$field = new WPBDP_FormField( $f );
|
323 |
+
$field->save();
|
324 |
+
}
|
325 |
+
}
|
326 |
+
|
327 |
+
public function get_short_names( $fieldid=null ) {
|
328 |
+
$names = get_option( 'wpbdp-field-short-names', false );
|
329 |
+
|
330 |
+
if ( !$names )
|
331 |
+
$names = $this->_calculate_short_names();
|
332 |
+
|
333 |
+
if ( $fieldid ) {
|
334 |
+
return isset( $names[ $fieldid ] ) ? $names[ $fieldid ] : null;
|
335 |
+
}
|
336 |
+
|
337 |
+
return $names;
|
338 |
+
}
|
339 |
+
|
340 |
+
public function _calculate_short_names() {
|
341 |
+
$fields = $this->get_fields();
|
342 |
+
$names = array();
|
343 |
+
|
344 |
+
foreach ( $fields as $field ) {
|
345 |
+
$name = strtolower( $field->get_label() );
|
346 |
+
$name = str_replace( array( ',', ';' ), '', $name );
|
347 |
+
$name = str_replace( array( ' ', '/' ), '-', $name );
|
348 |
+
|
349 |
+
if ( $name == 'images' || $name == 'image' || $name == 'username' || $name == 'featured_level' || $name == 'expires_on' || $name == 'sequence_id' || in_array( $name, $names, true ) ) {
|
350 |
+
$name = $field->get_id() . '/' . $name;
|
351 |
+
}
|
352 |
+
|
353 |
+
$names[ $field->get_id() ] = $name;
|
354 |
+
}
|
355 |
+
|
356 |
+
update_option( 'wpbdp-field-short-names', $names );
|
357 |
+
|
358 |
+
return $names;
|
359 |
+
}
|
360 |
+
|
361 |
+
public function set_fields_order( $fields_order = array() ) {
|
362 |
+
if ( ! $fields_order )
|
363 |
+
return false;
|
364 |
+
|
365 |
+
global $wpdb;
|
366 |
+
|
367 |
+
$total = count( $fields_order );
|
368 |
+
|
369 |
+
foreach ( $fields_order as $i => $field_id )
|
370 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_form_fields',
|
371 |
+
array( 'weight' => ( $total - $i ) ),
|
372 |
+
array( 'id' => $field_id ) );
|
373 |
+
|
374 |
+
return true;
|
375 |
+
}
|
376 |
+
|
377 |
+
}
|
378 |
+
|
379 |
+
/*
|
380 |
+
* Validation.
|
381 |
+
*/
|
382 |
+
|
383 |
+
function WPBDP_ValidationError( $msg, $stop_validation=false ) {
|
384 |
+
if ( $stop_validation )
|
385 |
+
return new WP_Error( 'wpbdp-validation-error-stop', $msg );
|
386 |
+
|
387 |
+
return new WP_Error( 'wpbdp-validation-error', $msg );
|
388 |
+
}
|
389 |
+
|
390 |
+
|
391 |
+
class WPBDP_FieldValidation {
|
392 |
+
|
393 |
+
private static $instance = null;
|
394 |
+
|
395 |
+
public static function instance() {
|
396 |
+
if (is_null(self::$instance)) {
|
397 |
+
self::$instance = new self;
|
398 |
+
}
|
399 |
+
|
400 |
+
return self::$instance;
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Get the set of publicly available validators.
|
405 |
+
* @return array associative array with validator name as key and display name as value
|
406 |
+
*/
|
407 |
+
public function get_validators() {
|
408 |
+
$validators = array(
|
409 |
+
'email' => _x('Email Validator', 'form-fields-api', 'WPBDM'),
|
410 |
+
'url' => _x('URL Validator', 'form-fields-api', 'WPBDM'),
|
411 |
+
'integer_number' => _x('Whole Number Validator', 'form-fields-api', 'WPBDM'),
|
412 |
+
'decimal_number' => _x('Decimal Number Validator', 'form-fields-api', 'WPBDM'),
|
413 |
+
'date_' => _x('Date Validator', 'form-fields-api', 'WPBDM')
|
414 |
+
);
|
415 |
+
|
416 |
+
return $validators;
|
417 |
+
}
|
418 |
+
|
419 |
+
public function validate_field( $field, $value, $validator, $args=array() ) {
|
420 |
+
$args['field-label'] = is_object( $field ) && $field ? $field->get_label() : _x( 'Field', 'form-fields-api validation', 'WPBDM' );
|
421 |
+
$args['field'] = $field;
|
422 |
+
|
423 |
+
return call_user_func( array( $this, $validator ) , $value, $args );
|
424 |
+
}
|
425 |
+
|
426 |
+
public function validate_value( $value, $validator, $args=array() ) {
|
427 |
+
return !is_wp_error( $this->validate_field( null, $value, $validator, $args ) );
|
428 |
+
}
|
429 |
+
|
430 |
+
/* Required validator */
|
431 |
+
private function required( $value, $args=array() ) {
|
432 |
+
$args = wp_parse_args( $args, array( 'allow_whitespace' => false, 'field' => null ) );
|
433 |
+
|
434 |
+
if ( $args['field'] && $args['field']->get_association() == 'category' ) {
|
435 |
+
if ( is_array( $value ) && count( $value ) == 1 && !$value[0] )
|
436 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is required.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
437 |
+
}
|
438 |
+
|
439 |
+
if ( ( $args['field'] && $args['field']->is_empty_value( $value ) ) || !$value || ( is_string( $value ) && !$args['allow_whitespace'] && !trim( $value ) ) )
|
440 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is required.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
441 |
+
}
|
442 |
+
|
443 |
+
/* URL Validator */
|
444 |
+
private function url( $value, $args=array() ) {
|
445 |
+
if ( is_array( $value ) ) $value = $value[0];
|
446 |
+
|
447 |
+
if ( function_exists( 'filter_var' ) ) {
|
448 |
+
if ( !filter_var( $value, FILTER_VALIDATE_URL ) ) {
|
449 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is badly formatted. Valid URL format required. Include http://', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
450 |
+
} else {
|
451 |
+
return;
|
452 |
+
}
|
453 |
+
}
|
454 |
+
|
455 |
+
if ( !preg_match( '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $value ) )
|
456 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is badly formatted. Valid URL format required. Include http://', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
457 |
+
}
|
458 |
+
|
459 |
+
/* EmailValidator */
|
460 |
+
private function email( $value, $args=array() ) {
|
461 |
+
$valid = false;
|
462 |
+
|
463 |
+
if ( function_exists( 'filter_var' ) ) {
|
464 |
+
$valid = filter_var( $value, FILTER_VALIDATE_EMAIL );
|
465 |
+
} else {
|
466 |
+
$valid = (bool) preg_match( '/^(?!(?>\x22?(?>\x22\x40|\x5C?[\x00-\x7F])\x22?){255,})(?!(?>\x22?\x5C?[\x00-\x7F]\x22?){65,}@)(?>[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+|(?>\x22(?>[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|\x5C[\x00-\x7F])*\x22))(?>\.(?>[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+|(?>\x22(?>[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|\x5C[\x00-\x7F])*\x22)))*@(?>(?>(?!.*[^.]{64,})(?>(?>xn--)?[a-z0-9]+(?>-[a-z0-9]+)*\.){0,126}(?>xn--)?[a-z0-9]+(?>-[a-z0-9]+)*)|(?:\[(?>(?>IPv6:(?>(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){7})|(?>(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?)))|(?>(?>IPv6:(?>(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){5}:)|(?>(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}:)?)))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\]))$/isD', $value );
|
467 |
+
}
|
468 |
+
|
469 |
+
if ( !$valid )
|
470 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is badly formatted. Valid Email format required.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
471 |
+
}
|
472 |
+
|
473 |
+
/* IntegerNumberValidator */
|
474 |
+
private function integer_number( $value, $args=array() ) {
|
475 |
+
if ( !ctype_digit( $value ) )
|
476 |
+
return WPBDP_ValidationError( sprintf( _x( '%s must be a number. Decimal values are not allowed.', 'form-fields-api validation', 'WPBDM' ), esc_attr ( $args['field-label'] ) ) );
|
477 |
+
}
|
478 |
+
|
479 |
+
/* DecimalNumberValidator */
|
480 |
+
private function decimal_number( $value, $args=array() ) {
|
481 |
+
if ( !is_numeric( $value ) )
|
482 |
+
return WPBDP_ValidationError( sprintf( _x( '%s must be a number.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
483 |
+
}
|
484 |
+
|
485 |
+
/* DateValidator */
|
486 |
+
private function date_( $value, $args=array() ) {
|
487 |
+
$args = wp_parse_args( $args, array( 'format' => 'm/d/Y' ) );
|
488 |
+
|
489 |
+
// TODO: validate with format
|
490 |
+
list( $m, $d, $y ) = explode( '/', $value );
|
491 |
+
|
492 |
+
if ( !is_numeric( $m ) || !is_numeric( $d ) || !is_numeric( $y ) || !checkdate( $m, $d, $y ) )
|
493 |
+
return WPBDP_ValidationError( sprintf( _x( '%s must be in the format MM/DD/YYYY.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ) ) );
|
494 |
+
}
|
495 |
+
|
496 |
+
private function any_of( $value, $args=array() ) {
|
497 |
+
$args = wp_parse_args( $args, array( 'values' => array(), 'formatter' => create_function( '$x', 'return join(",", $x);' ) ) );
|
498 |
+
extract( $args, EXTR_SKIP );
|
499 |
+
|
500 |
+
if ( is_string( $values ) )
|
501 |
+
$values = explode( ',', $values );
|
502 |
+
|
503 |
+
if ( !in_array( $value, $values ) )
|
504 |
+
return WPBDP_ValidationError( sprintf( _x( '%s is invalid. Value most be one of %s.', 'form-fields-api validation', 'WPBDM' ), esc_attr( $args['field-label'] ), call_user_func( $formatter, $values ) ) );
|
505 |
+
}
|
506 |
+
|
507 |
+
}
|
508 |
+
|
509 |
+
|
510 |
+
}
|
511 |
+
|
512 |
+
|
513 |
+
|
514 |
+
/**
|
515 |
+
* @since 2.3
|
516 |
+
* @see WPBDP_FormFields::find_fields()
|
517 |
+
*/
|
518 |
+
function &wpbdp_get_form_fields( $args=array() ) {
|
519 |
+
global $wpbdp;
|
520 |
+
$fields = $wpbdp->formfields->find_fields( $args );
|
521 |
+
|
522 |
+
if ( ! $fields )
|
523 |
+
$fields = array();
|
524 |
+
|
525 |
+
return $fields;
|
526 |
+
}
|
527 |
+
|
528 |
+
/**
|
529 |
+
* @since 2.3
|
530 |
+
* @see WPBDP_FormFields::get_field()
|
531 |
+
*/
|
532 |
+
function wpbdp_get_form_field( $id ) {
|
533 |
+
global $wpbdp;
|
534 |
+
return $wpbdp->formfields->get_field( $id );
|
535 |
+
}
|
536 |
+
|
537 |
+
/**
|
538 |
+
* Validates a value against a given validator.
|
539 |
+
* @param mixed $value
|
540 |
+
* @param string $validator one of the registered validators.
|
541 |
+
* @param array $args optional arguments to be passed to the validator.
|
542 |
+
* @return boolean True if value validates, False otherwise.
|
543 |
+
* @since 2.3
|
544 |
+
* @see WPBDP_FieldValidation::validate_value()
|
545 |
+
*/
|
546 |
+
function wpbdp_validate_value( $value, $validator, $args=array() ) {
|
547 |
+
$validation = WPBDP_FieldValidation::instance();
|
548 |
+
return $validation->validate_value( $value, $validator, $args );
|
549 |
+
}
|
550 |
+
|
core/gateways-dummy.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once ( WPBDP_PATH . 'core/class-gateway.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Dummy gateway used for testing.
|
6 |
+
* @since 3.5.3
|
7 |
+
*/
|
8 |
+
class WPBDP_Dummy_Gateway extends WPBDP_Payment_Gateway {
|
9 |
+
|
10 |
+
public function get_id() {
|
11 |
+
return 'dummy';
|
12 |
+
}
|
13 |
+
|
14 |
+
public function get_name() {
|
15 |
+
return _x( 'Dummy', 'dummy gateway', 'WPBDM' );
|
16 |
+
}
|
17 |
+
|
18 |
+
public function get_integration_method() {
|
19 |
+
return WPBDP_Payment_Gateway::INTEGRATION_BUTTON;
|
20 |
+
}
|
21 |
+
|
22 |
+
public function get_supported_currencies() {
|
23 |
+
return array( 'AUD', 'BRL', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'JPY', 'MYR', 'MXN', 'NOK',
|
24 |
+
'NZD', 'PHP', 'PLN', 'GBP', 'RUB', 'SGD', 'SEK', 'CHF', 'TWD', 'THB', 'TRY', 'USD' );
|
25 |
+
}
|
26 |
+
|
27 |
+
public function get_capabilities() {
|
28 |
+
return array( 'recurring' );
|
29 |
+
}
|
30 |
+
|
31 |
+
public function validate_config() {
|
32 |
+
return array();
|
33 |
+
}
|
34 |
+
|
35 |
+
public function render_integration( &$payment ) {
|
36 |
+
$html = '';
|
37 |
+
$html .= sprintf( '<form action="%s" method="post">', $this->get_url( $payment, 'process' ) );
|
38 |
+
$html .= '<b><u>' . _x( 'Dummy Gateway', 'dummy gateway', 'WPBDM' ) . '</u></b><br />';
|
39 |
+
$html .= '<b>' . _x( 'New Status:', 'dummy gateway', 'WPBDM' ) . '</b> ';
|
40 |
+
$html .= sprintf( '<label><input type="radio" name="status" value="completed" checked="checked" /> %s</label> ',
|
41 |
+
_x( 'Completed', 'dummy gateway', 'WPBDM' ) );
|
42 |
+
$html .= sprintf( '<label><input type="radio" name="status" value="pending" /> %s</label> ',
|
43 |
+
_x( 'Pending', 'dummy gateway', 'WPBDM' ) );
|
44 |
+
$html .= sprintf( '<label><input type="radio" name="status" value="canceled" /> %s</label> ',
|
45 |
+
_x( 'Canceled', 'dummy gateway', 'WPBDM' ) );
|
46 |
+
$html .= sprintf( '<label><input type="radio" name="status" value="rejected" /> %s</label> ',
|
47 |
+
_x( 'Rejected', 'dummy gateway', 'WPBDM' ) );
|
48 |
+
$html .= '<br />';
|
49 |
+
$html .= sprintf( '<input type="submit" value="%s"/>', _x( 'Process Payment', 'dummy gateway', 'WPBDM' ) );
|
50 |
+
$html .= '<hr />';
|
51 |
+
$html .= '<textarea rows="10" style="width: 100%; font-family: monospace; font-size: 12px;">';
|
52 |
+
$html .= esc_textarea( print_r( $payment, 1 ) );
|
53 |
+
$html .= '</textarea>';
|
54 |
+
$html .= '</form>';
|
55 |
+
|
56 |
+
return $html;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function process( &$payment, $action ) {
|
60 |
+
if ( ! $payment->is_pending() )
|
61 |
+
return;
|
62 |
+
|
63 |
+
$new_status = isset( $_POST['status'] ) ? $_POST['status'] : '';
|
64 |
+
|
65 |
+
if ( ! $new_status )
|
66 |
+
return;
|
67 |
+
|
68 |
+
$payment->set_status( $new_status, WPBDP_Payment::HANDLER_GATEWAY );
|
69 |
+
$payment->save();
|
70 |
+
|
71 |
+
wp_redirect( $payment->get_redirect_url() );
|
72 |
+
}
|
73 |
+
|
74 |
+
}
|
core/gateways-googlewallet.php
ADDED
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-gateway.php' );
|
3 |
+
|
4 |
+
if ( ! class_exists( 'JWT' ) )
|
5 |
+
require_once( WPBDP_PATH . 'vendors/jwt/JWT.php' );
|
6 |
+
|
7 |
+
|
8 |
+
class WPBDP_Google_Wallet_Gateway extends WPBDP_Payment_Gateway {
|
9 |
+
|
10 |
+
const LIVE_JS = 'https://wallet.google.com/inapp/lib/buy.js';
|
11 |
+
const SANDBOX_JS = 'https://sandbox.google.com/checkout/inapp/lib/buy.js';
|
12 |
+
|
13 |
+
public function get_id() {
|
14 |
+
return 'googlewallet';
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_name() {
|
18 |
+
return __( 'Google Wallet', 'google-wallet', 'WPBDM' );
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_integration_method() {
|
22 |
+
return WPBDP_Payment_Gateway::INTEGRATION_BUTTON;
|
23 |
+
}
|
24 |
+
|
25 |
+
public function get_supported_currencies() {
|
26 |
+
return array( 'USD', 'EUR', 'CAD', 'GBP', 'AUD', 'HKD', 'JPY', 'DKK', 'NOK', 'SEK' );
|
27 |
+
}
|
28 |
+
|
29 |
+
public function get_capabilities() {
|
30 |
+
return array( 'recurring' );
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @since 3.4.2
|
35 |
+
*/
|
36 |
+
public function setup_payment( &$payment ) {
|
37 |
+
if ( ! $payment->has_item_type( 'recurring_fee' ) )
|
38 |
+
return;
|
39 |
+
|
40 |
+
$items = $payment->get_items();
|
41 |
+
|
42 |
+
// XXX: Google Wallet is full of limitations:
|
43 |
+
// - It doesn't handle subscription frequencies different than 30 days, so we must make those kind of fees
|
44 |
+
// non recurring.
|
45 |
+
// - It doesn't notify of renewals so we must assume all recurring fees are of indefinite length until we
|
46 |
+
// receive a cancellation notification.
|
47 |
+
foreach ( $items as &$item ) {
|
48 |
+
if ( 'recurring_fee' != $item->item_type )
|
49 |
+
continue;
|
50 |
+
|
51 |
+
if ( $item->data['fee_days'] != 30 ) {
|
52 |
+
$item->item_type = 'fee';
|
53 |
+
continue;
|
54 |
+
}
|
55 |
+
|
56 |
+
$item->data['fee_days'] = 0;
|
57 |
+
}
|
58 |
+
|
59 |
+
$payment->update_items( $items );
|
60 |
+
}
|
61 |
+
|
62 |
+
public function register_config( &$settings ) {
|
63 |
+
global $wpbdp;
|
64 |
+
|
65 |
+
$desc = '';
|
66 |
+
|
67 |
+
if ( wpbdp_get_option( 'listing-renewal-auto' ) ) {
|
68 |
+
$msg = _x( 'For recurring payments to work you need to <a>specify a postback URL</a> in your Google Wallet settings.', 'google-wallet', 'WPBDM' ) . '<br /> ' .
|
69 |
+
_x( 'Please use %s as the postback URL.', 'google-wallet', 'WPBDM' );
|
70 |
+
$url = '<b>' . $wpbdp->payments->gateways['googlewallet']->get_gateway_url() . '</b>';
|
71 |
+
$desc .= str_replace( array( '<a>',
|
72 |
+
'%s' ),
|
73 |
+
array( '<a href="https://developers.google.com/wallet/digital/docs/postback" target="_blank">',
|
74 |
+
$url ),
|
75 |
+
$msg );
|
76 |
+
}
|
77 |
+
|
78 |
+
$s = $settings->add_section( 'payment',
|
79 |
+
'googlewallet',
|
80 |
+
$this->get_name(),
|
81 |
+
$desc );
|
82 |
+
$settings->add_setting( $s,
|
83 |
+
'googlewallet',
|
84 |
+
__( 'Activate Google Wallet?', 'google-wallet', 'WPBDM' ),
|
85 |
+
'boolean',
|
86 |
+
false );
|
87 |
+
$settings->add_setting( $s,
|
88 |
+
'googlewallet-seller-id',
|
89 |
+
__( 'Seller Identifier', 'google-wallet', 'WPBDM' ) );
|
90 |
+
$settings->register_dep( 'googlewallet-seller-id', 'requires-true', 'googlewallet' );
|
91 |
+
|
92 |
+
$settings->add_setting( $s,
|
93 |
+
'googlewallet-seller-secret',
|
94 |
+
__( 'Seller Secret', 'google-wallet', 'WPBDM' ) );
|
95 |
+
$settings->register_dep( 'googlewallet-seller-secret', 'requires-true', 'googlewallet' );
|
96 |
+
}
|
97 |
+
|
98 |
+
public function validate_config() {
|
99 |
+
$seller_id = wpbdp_get_option( 'googlewallet-seller-id' );
|
100 |
+
$seller_secret = wpbdp_get_option( 'googlewallet-seller-secret' );
|
101 |
+
|
102 |
+
$errors = array();
|
103 |
+
|
104 |
+
if ( ! $seller_id )
|
105 |
+
$errors[] = _x( 'Seller ID is missing.', 'google-wallet', 'WPBDM' );
|
106 |
+
|
107 |
+
if ( ! $seller_secret )
|
108 |
+
$errors[] = _x( 'Seller Secret is missing.', 'google-wallet', 'WPBDM' );
|
109 |
+
|
110 |
+
return $errors;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function render_integration( &$payment ) {
|
114 |
+
// See https://developers.google.com/commerce/wallet/digital/docs/jsreference#jwt.
|
115 |
+
|
116 |
+
$payload = array();
|
117 |
+
$payload['iss'] = wpbdp_get_option( 'googlewallet-seller-id' );
|
118 |
+
$payload['aud'] = 'Google';
|
119 |
+
$payload['exp'] = time() + 900; // Item expires in 15 mins.
|
120 |
+
$payload['iat'] = time();
|
121 |
+
|
122 |
+
if ( $payment->has_item_type( 'recurring_fee' ) ) {
|
123 |
+
$regular_items = array();
|
124 |
+
$recurring_item = null;
|
125 |
+
|
126 |
+
foreach ( $payment->get_items() as $item ) {
|
127 |
+
if ( $item->item_type == 'recurring_fee' ) {
|
128 |
+
$recurring_item = $item;
|
129 |
+
continue;
|
130 |
+
}
|
131 |
+
|
132 |
+
$regular_items[] = $item;
|
133 |
+
}
|
134 |
+
|
135 |
+
$payload['typ'] = 'google/payments/inapp/subscription/v1';
|
136 |
+
$payload['request'] = array();
|
137 |
+
$payload['request']['name'] = $regular_items ? _x( 'One time payment + recurring payment for renewal fees', 'google-wallet', 'WPBDM' ) : $recurring_item->description;
|
138 |
+
$payload['request']['sellerData'] = 'payment_id=' . $payment->get_id() . '&listing_id=' . $payment->get_listing_id();
|
139 |
+
$payload['request']['recurrence'] = array(
|
140 |
+
'price' => number_format( $recurring_item->amount, 2, '.', '' ),
|
141 |
+
'currencyCode' => $payment->get_currency_code(),
|
142 |
+
'frequency' => 'monthly'
|
143 |
+
);
|
144 |
+
|
145 |
+
if ( $regular_items ) {
|
146 |
+
$payload['request']['initialPayment'] = array(
|
147 |
+
'price' => number_format( $regular_items[0]->amount, 2, '.', '' ),
|
148 |
+
'currencyCode' => $payment->get_currency_code(),
|
149 |
+
'paymentType' => 'free_trial'
|
150 |
+
);
|
151 |
+
}
|
152 |
+
} else {
|
153 |
+
$payload['typ'] = 'google/payments/inapp/item/v1';
|
154 |
+
$payload['request'] = array(
|
155 |
+
'name' => $payment->get_short_description(),
|
156 |
+
'description' => $payment->get_description(),
|
157 |
+
'price' => round( $payment->get_total(), 0 ),
|
158 |
+
'currencyCode' => $payment->get_currency_code(),
|
159 |
+
'sellerData' => 'payment_id=' . $payment->get_id() . '&listing_id=' . $payment->get_listing_id()
|
160 |
+
);
|
161 |
+
}
|
162 |
+
|
163 |
+
$token = JWT::encode( $payload, wpbdp_get_option( 'googlewallet-seller-secret' ) );
|
164 |
+
|
165 |
+
// HTML button.
|
166 |
+
$html = '';
|
167 |
+
$html .= sprintf( '<script src="%s"></script>', wpbdp_get_option( 'payments-test-mode' ) ? self::SANDBOX_JS : self::LIVE_JS );
|
168 |
+
|
169 |
+
$html .= sprintf( '<form action="%s" method="POST">', $this->get_url( $payment, 'process' ) );
|
170 |
+
$html .= '<input type="hidden" name="success" value="1" />';
|
171 |
+
$html .= '<input type="hidden" name="error" value="" />';
|
172 |
+
$html .= sprintf( '<input type="hidden" name="jwt" value="%s" />', $token );
|
173 |
+
$html .= '<input type="hidden" name="order_id" value="" />';
|
174 |
+
$html .= sprintf( '<a href="#" id="googlewallet-buy">',
|
175 |
+
esc_attr( $token ),
|
176 |
+
esc_url( $this->get_url( $payment, 'process' ) )
|
177 |
+
);
|
178 |
+
$html .= sprintf( '<img src="%s" />', WPBDP_URL . 'core/images/googlewallet.gif' );
|
179 |
+
$html .= '</a>';
|
180 |
+
$html .= '</form>';
|
181 |
+
|
182 |
+
return $html;
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* @since 3.4.2
|
187 |
+
*/
|
188 |
+
public function process_generic( $action = '' ) {
|
189 |
+
if ( 'postback' != $action )
|
190 |
+
return;
|
191 |
+
|
192 |
+
$jwt = JWT::decode( wpbdp_getv( $_REQUEST, 'jwt', '' ), wpbdp_get_option( 'googlewallet-seller-secret' ) );
|
193 |
+
|
194 |
+
if ( ! is_object( $jwt ) || ! isset( $jwt->request) || ! isset( $jwt->request->sellerData ) || ! isset( $jwt->response ) )
|
195 |
+
die();
|
196 |
+
|
197 |
+
parse_str( $jwt->request->sellerData, $data );
|
198 |
+
|
199 |
+
if ( ! isset( $data['payment_id'] ) )
|
200 |
+
die();
|
201 |
+
|
202 |
+
$payment_id = intval( $data['payment_id'] );
|
203 |
+
$payment = WPBDP_Payment::get( $payment_id );
|
204 |
+
|
205 |
+
if ( 'googlewallet' != $payment->get_gateway() )
|
206 |
+
die();
|
207 |
+
|
208 |
+
if ( 'SUBSCRIPTION_CANCELED' == $jwt->response->statusCode ) {
|
209 |
+
$payment->cancel_recurring();
|
210 |
+
}
|
211 |
+
|
212 |
+
die();
|
213 |
+
}
|
214 |
+
|
215 |
+
public function process( &$payment, $action ) {
|
216 |
+
if ( ! $payment->is_pending() )
|
217 |
+
return;
|
218 |
+
|
219 |
+
$a = '';
|
220 |
+
|
221 |
+
if ( isset( $_REQUEST['success'] ) && 1 == $_REQUEST['success'] )
|
222 |
+
$a = 'success';
|
223 |
+
elseif ( isset( $_REQUEST['postback'] ) && 1 == $_REQUEST['postback'] )
|
224 |
+
$a = 'postback';
|
225 |
+
elseif ( isset( $_REQUEST['error'] ) && ! empty( $_REQUEST['error'] ) && ( ! isset( $_REQUEST['success'] ) || 0 == $_REQUEST['success'] ) )
|
226 |
+
$a = 'error';
|
227 |
+
|
228 |
+
switch ( $a ) {
|
229 |
+
case 'success':
|
230 |
+
$jwt = JWT::decode( wpbdp_getv( $_REQUEST, 'jwt', '' ), wpbdp_get_option( 'googlewallet-seller-secret' ) );
|
231 |
+
|
232 |
+
if ( ! $this->validate_jwt( $jwt, $payment ) ) {
|
233 |
+
$payment->add_error( _x( 'Payment was rejected because internal data does not look like a valid Google Wallet transaction.', 'google-wallet', 'WPBDM' ) );
|
234 |
+
$payment->set_status( WPBDP_Payment::STATUS_REJECTED, WPBDP_Payment::HANDLER_GATEWAY );
|
235 |
+
} else {
|
236 |
+
$payment->set_status( WPBDP_Payment::STATUS_COMPLETED, WPBDP_Payment::HANDLER_GATEWAY );
|
237 |
+
}
|
238 |
+
|
239 |
+
break;
|
240 |
+
|
241 |
+
case 'error':
|
242 |
+
$error = $_REQUEST['error'];
|
243 |
+
|
244 |
+
switch ( $error ) {
|
245 |
+
case 'MERCHANT_ERROR':
|
246 |
+
case 'POSTBACK_ERROR':
|
247 |
+
case 'INTERNAL_SERVER_ERROR':
|
248 |
+
$payment->add_error( _x( 'Payment has been rejected because an internal error occurred.', 'google-wallet', 'WPBDM' ) );
|
249 |
+
$payment->set_status( WPBDP_Payment::STATUS_REJECTED, WPBDP_Payment::HANDLER_GATEWAY );
|
250 |
+
|
251 |
+
break;
|
252 |
+
case 'PURCHASE_CANCELED':
|
253 |
+
case 'PURCHASE_CANCELLED':
|
254 |
+
$payment->add_error( _x( "The transaction has been canceled at user's request.", 'google-wallet', 'WPBDM' ) );
|
255 |
+
$payment->set_status( WPBDP_Payment::STATUS_CANCELED, WPBDP_Payment::HANDLER_GATEWAY );
|
256 |
+
|
257 |
+
break;
|
258 |
+
}
|
259 |
+
|
260 |
+
break;
|
261 |
+
|
262 |
+
case 'postback':
|
263 |
+
// TODO: implement postback URL support.
|
264 |
+
break;
|
265 |
+
|
266 |
+
default:
|
267 |
+
break;
|
268 |
+
}
|
269 |
+
|
270 |
+
$payment->save();
|
271 |
+
|
272 |
+
wp_redirect( $payment->get_redirect_url() );
|
273 |
+
}
|
274 |
+
|
275 |
+
private function validate_jwt( &$jwt, &$payment ) {
|
276 |
+
if ( !isset( $jwt->request ) || !isset( $jwt->response ) )
|
277 |
+
return false;
|
278 |
+
|
279 |
+
if ( !isset( $jwt->iss ) || $jwt->iss != 'Google' )
|
280 |
+
return false;
|
281 |
+
|
282 |
+
if ( !isset( $jwt->aud ) || $jwt->aud != wpbdp_get_option( 'googlewallet-seller-id' ) )
|
283 |
+
return false;
|
284 |
+
|
285 |
+
// Check seller data.
|
286 |
+
$seller_data = isset( $jwt->request->sellerData ) ? $jwt->request->sellerData : null;
|
287 |
+
if ( !$seller_data )
|
288 |
+
return false;
|
289 |
+
|
290 |
+
parse_str( $seller_data, $data );
|
291 |
+
|
292 |
+
if ( $data['payment_id'] != $payment->get_id() || $data['listing_id'] != $payment->get_listing_id() )
|
293 |
+
return false;
|
294 |
+
|
295 |
+
// Check price.
|
296 |
+
if ( round( $payment->get_total(), 0 ) != $jwt->request->price )
|
297 |
+
return false;
|
298 |
+
|
299 |
+
// Check order ID.
|
300 |
+
if ( !isset( $jwt->response->orderId ) )
|
301 |
+
return false;
|
302 |
+
|
303 |
+
return true;
|
304 |
+
}
|
305 |
+
|
306 |
+
public static function register_gateway( &$payments ) {
|
307 |
+
$payments->register_gateway( 'googlewallet', __CLASS__ );
|
308 |
+
}
|
309 |
+
|
310 |
+
}
|
311 |
+
|
312 |
+
add_action( 'wpbdp_register_gateways', array( 'WPBDP_Google_Wallet_Gateway', 'register_gateway' ) );
|
core/images/default-image-big.gif
ADDED
Binary file
|
core/images/default.png
ADDED
Binary file
|
core/images/featuredlisting.png
ADDED
Binary file
|
core/images/googlewallet.gif
ADDED
Binary file
|
core/index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php
|
core/installer.php
ADDED
@@ -0,0 +1,794 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_Installer {
|
4 |
+
|
5 |
+
const DB_VERSION = '4.0';
|
6 |
+
|
7 |
+
private $installed_version = null;
|
8 |
+
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
$this->installed_version = get_option( 'wpbdp-db-version', get_option( 'wpbusdirman_db_version', null ) );
|
12 |
+
}
|
13 |
+
|
14 |
+
public function install() {
|
15 |
+
// schedule expiration hook if needed
|
16 |
+
if (!wp_next_scheduled('wpbdp_listings_expiration_check')) {
|
17 |
+
wpbdp_log('Expiration check was not in schedule. Scheduling.');
|
18 |
+
wp_schedule_event(current_time('timestamp'), 'hourly', 'wpbdp_listings_expiration_check');
|
19 |
+
} else {
|
20 |
+
wpbdp_log('Expiration check was in schedule. Nothing to do.');
|
21 |
+
}
|
22 |
+
|
23 |
+
if ( self::DB_VERSION == $this->installed_version )
|
24 |
+
return;
|
25 |
+
|
26 |
+
$this->update_database_schema();
|
27 |
+
|
28 |
+
if ( $this->installed_version ) {
|
29 |
+
wpbdp_log('WPBDP is already installed.');
|
30 |
+
$this->_update();
|
31 |
+
} else {
|
32 |
+
wpbdp_log('New installation. Creating default form fields.');
|
33 |
+
global $wpbdp;
|
34 |
+
|
35 |
+
// Create default category.
|
36 |
+
wp_insert_term( _x( 'General', 'default category name', 'WPBDM' ), WPBDP_CATEGORY_TAX );
|
37 |
+
|
38 |
+
$wpbdp->formfields->create_default_fields();
|
39 |
+
|
40 |
+
add_option( 'wpbdp-show-drip-pointer', 1 );
|
41 |
+
add_option( 'wpbdp-show-tracking-pointer', 1 );
|
42 |
+
}
|
43 |
+
|
44 |
+
delete_option('wpbusdirman_db_version');
|
45 |
+
update_option('wpbdp-db-version', self::DB_VERSION);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Builds the SQL queries (without running them) used to create all of the required database tables for BD.
|
50 |
+
* Calls the `wpbdp_database_schema` filter that allows plugins to modify the schema.
|
51 |
+
* @return array An associative array of (non prefixed)table => SQL items.
|
52 |
+
* @since 3.3
|
53 |
+
*/
|
54 |
+
public function get_database_schema() {
|
55 |
+
global $wpdb;
|
56 |
+
|
57 |
+
$schema = array();
|
58 |
+
|
59 |
+
$schema['form_fields'] = "CREATE TABLE {$wpdb->prefix}wpbdp_form_fields (
|
60 |
+
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
|
61 |
+
label varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
62 |
+
description varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
|
63 |
+
field_type varchar(100) NOT NULL,
|
64 |
+
association varchar(100) NOT NULL,
|
65 |
+
validators text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
|
66 |
+
weight int(5) NOT NULL DEFAULT 0,
|
67 |
+
display_flags text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
|
68 |
+
field_data blob NULL
|
69 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
70 |
+
|
71 |
+
$schema['fees'] = "CREATE TABLE {$wpdb->prefix}wpbdp_fees (
|
72 |
+
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
|
73 |
+
label varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
74 |
+
amount decimal(10,2) NOT NULL DEFAULT 0.00,
|
75 |
+
days smallint unsigned NOT NULL DEFAULT 0,
|
76 |
+
images smallint unsigned NOT NULL DEFAULT 0,
|
77 |
+
categories blob NOT NULL,
|
78 |
+
extra_data blob NULL,
|
79 |
+
weight int(5) NOT NULL DEFAULT 0
|
80 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
81 |
+
|
82 |
+
$schema['payments'] = "CREATE TABLE {$wpdb->prefix}wpbdp_payments (
|
83 |
+
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
|
84 |
+
listing_id bigint(20) NOT NULL DEFAULT 0,
|
85 |
+
gateway varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
|
86 |
+
currency_code varchar(3) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'USD',
|
87 |
+
amount decimal(10,2) NOT NULL DEFAULT 0.00,
|
88 |
+
status varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
89 |
+
created_on timestamp NOT NULL,
|
90 |
+
processed_on timestamp NULL,
|
91 |
+
processed_by varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
|
92 |
+
payerinfo blob NULL,
|
93 |
+
extra_data longblob NULL,
|
94 |
+
notes longblob NULL
|
95 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
96 |
+
|
97 |
+
$schema['payments_items'] = "CREATE TABLE {$wpdb->prefix}wpbdp_payments_items (
|
98 |
+
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
|
99 |
+
payment_id bigint(20) NOT NULL,
|
100 |
+
amount decimal(10,2) NOT NULL DEFAULT 0.00,
|
101 |
+
item_type varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'charge',
|
102 |
+
description varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'Charge',
|
103 |
+
rel_id_1 bigint(20) NULL,
|
104 |
+
rel_id_2 bigint(20) NULL,
|
105 |
+
data longblob NULL
|
106 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci";
|
107 |
+
|
108 |
+
$schema['listing_fees'] = "CREATE TABLE {$wpdb->prefix}wpbdp_listing_fees (
|
109 |
+
id bigint(20) PRIMARY KEY AUTO_INCREMENT,
|
110 |
+
listing_id bigint(20) NOT NULL,
|
111 |
+
category_id bigint(20) NOT NULL,
|
112 |
+
fee_id bigint(20) NULL,
|
113 |
+
fee_days smallint unsigned NOT NULL,
|
114 |
+
fee_images smallint unsigned NOT NULL DEFAULT 0,
|
115 |
+
expires_on timestamp NULL DEFAULT NULL,
|
116 |
+
email_sent tinyint(1) NOT NULL DEFAULT 0,
|
117 |
+
recurring tinyint(1) NOT NULL DEFAULT 0,
|
118 |
+
recurring_id varchar(255) NULL,
|
119 |
+
recurring_data blob NULL
|
120 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
121 |
+
|
122 |
+
$schema['submit_state'] = "CREATE TABLE {$wpdb->prefix}wpbdp_submit_state (
|
123 |
+
id varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci PRIMARY KEY,
|
124 |
+
state longblob NOT NULL,
|
125 |
+
updated_on datetime NOT NULL
|
126 |
+
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
127 |
+
|
128 |
+
return apply_filters( 'wpbdp_database_schema', $schema );
|
129 |
+
}
|
130 |
+
|
131 |
+
public function update_database_schema() {
|
132 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
133 |
+
|
134 |
+
wpbdp_log( 'Running dbDelta.' );
|
135 |
+
|
136 |
+
$schema = $this->get_database_schema();
|
137 |
+
|
138 |
+
foreach ( $schema as $table_sql )
|
139 |
+
dbDelta( $table_sql );
|
140 |
+
}
|
141 |
+
|
142 |
+
public function _update() {
|
143 |
+
global $wpbdp;
|
144 |
+
|
145 |
+
if ( get_option( 'wpbdp-manual-upgrade-pending', false ) )
|
146 |
+
return;
|
147 |
+
|
148 |
+
$upgrade_routines = array( '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '3.1', '3.2', '3.4', '3.5', '3.6', '3.7', '3.9', '4.0' );
|
149 |
+
|
150 |
+
foreach ( $upgrade_routines as $v ) {
|
151 |
+
if ( version_compare( $this->installed_version, $v ) < 0 ) {
|
152 |
+
wpbdp_log( sprintf( 'Running upgrade routine for version %s', $v ) );
|
153 |
+
$_v = str_replace( '.', '_', $v );
|
154 |
+
call_user_func( array( $this, 'upgrade_to_' . $_v ) );
|
155 |
+
update_option('wpbdp-db-version', $v);
|
156 |
+
|
157 |
+
if ( get_option( 'wpbdp-manual-upgrade-pending', false ) )
|
158 |
+
break;
|
159 |
+
}
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
public function request_manual_upgrade( $callback ) {
|
164 |
+
update_option( 'wpbdp-manual-upgrade-pending', $callback );
|
165 |
+
}
|
166 |
+
|
167 |
+
public function setup_manual_upgrade() {
|
168 |
+
$manual_upgrade = get_option( 'wpbdp-manual-upgrade-pending', false );
|
169 |
+
|
170 |
+
if ( ! $manual_upgrade )
|
171 |
+
return;
|
172 |
+
|
173 |
+
new WPBDP_Installer_Manual_Upgrade( $this, $manual_upgrade );
|
174 |
+
}
|
175 |
+
|
176 |
+
|
177 |
+
/*
|
178 |
+
* Upgrade routines.
|
179 |
+
*/
|
180 |
+
|
181 |
+
public function upgrade_to_2_0() {
|
182 |
+
global $wpdb;
|
183 |
+
global $wpbdp;
|
184 |
+
|
185 |
+
$wpbdp->settings->upgrade_options();
|
186 |
+
wpbdp_log('WPBDP settings updated to 2.0-style');
|
187 |
+
|
188 |
+
// make directory-related metadata hidden
|
189 |
+
$old_meta_keys = array(
|
190 |
+
'termlength', 'image', 'listingfeeid', 'sticky', 'thumbnail', 'paymentstatus', 'buyerfirstname', 'buyerlastname',
|
191 |
+
'paymentflag', 'payeremail', 'paymentgateway', 'totalallowedimages', 'costoflisting'
|
192 |
+
);
|
193 |
+
|
194 |
+
foreach ($old_meta_keys as $meta_key) {
|
195 |
+
$query = $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s AND {$wpdb->postmeta}.post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = %s)",
|
196 |
+
'_wpbdp_' . $meta_key, $meta_key, 'wpbdm-directory');
|
197 |
+
$wpdb->query($query);
|
198 |
+
}
|
199 |
+
|
200 |
+
wpbdp_log('Made WPBDP directory metadata hidden attributes');
|
201 |
+
}
|
202 |
+
|
203 |
+
public function upgrade_to_2_1() {
|
204 |
+
global $wpdb;
|
205 |
+
|
206 |
+
/* This is only to make this routine work for BD 3.0. It's not necessary in other versions. */
|
207 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields ADD COLUMN validator VARCHAR(255) NULL;" );
|
208 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields ADD COLUMN display_options BLOB NULL;" );
|
209 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields ADD COLUMN is_required TINYINT(1) NOT NULL DEFAULT 0;" );
|
210 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields ADD COLUMN type VARCHAR(255) NOT NULL;" );
|
211 |
+
|
212 |
+
static $pre_2_1_types = array(null, 'textfield', 'select', 'textarea', 'radio', 'multiselect', 'checkbox');
|
213 |
+
static $pre_2_1_validators = array(
|
214 |
+
'email' => 'EmailValidator',
|
215 |
+
'url' => 'URLValidator',
|
216 |
+
'missing' => null, /* not really used */
|
217 |
+
'numericwhole' => 'IntegerNumberValidator',
|
218 |
+
'numericdeci' => 'DecimalNumberValidator',
|
219 |
+
'date' => 'DateValidator'
|
220 |
+
);
|
221 |
+
static $pre_2_1_associations = array(
|
222 |
+
'title' => 'title',
|
223 |
+
'description' => 'content',
|
224 |
+
'category' => 'category',
|
225 |
+
'excerpt' => 'excerpt',
|
226 |
+
'meta' => 'meta',
|
227 |
+
'tags' => 'tags'
|
228 |
+
);
|
229 |
+
|
230 |
+
$field_count = $wpdb->get_var(
|
231 |
+
sprintf("SELECT COUNT(*) FROM {$wpdb->prefix}options WHERE option_name LIKE '%%%s%%'", 'wpbusdirman_postform_field_label'));
|
232 |
+
|
233 |
+
for ($i = 1; $i <= $field_count; $i++) {
|
234 |
+
$label = get_option('wpbusdirman_postform_field_label_' . $i);
|
235 |
+
$type = get_option('wpbusdirman_postform_field_type_'. $i);
|
236 |
+
$validation = get_option('wpbusdirman_postform_field_validation_'. $i);
|
237 |
+
$association = get_option('wpbusdirman_postform_field_association_'. $i);
|
238 |
+
$required = strtolower(get_option('wpbusdirman_postform_field_required_'. $i));
|
239 |
+
$show_in_excerpt = strtolower(get_option('wpbusdirman_postform_field_showinexcerpt_'. $i));
|
240 |
+
$hide_field = strtolower(get_option('wpbusdirman_postform_field_hide_'. $i));
|
241 |
+
$options = get_option('wpbusdirman_postform_field_options_'. $i);
|
242 |
+
|
243 |
+
$newfield = array();
|
244 |
+
$newfield['label'] = $label;
|
245 |
+
$newfield['type'] = wpbdp_getv($pre_2_1_types, intval($type), 'textfield');
|
246 |
+
$newfield['validator'] = wpbdp_getv($pre_2_1_validators, $validation, null);
|
247 |
+
$newfield['association'] = wpbdp_getv($pre_2_1_associations, $association, 'meta');
|
248 |
+
$newfield['is_required'] = $required == 'yes' ? true : false;
|
249 |
+
$newfield['display_options'] = serialize(
|
250 |
+
array('show_in_excerpt' => $show_in_excerpt == 'yes' ? true : false,
|
251 |
+
'hide_field' => $hide_field == 'yes' ? true : false)
|
252 |
+
);
|
253 |
+
$newfield['field_data'] = $options ? serialize(array('options' => explode(',', $options))) : null;
|
254 |
+
|
255 |
+
if ($wpdb->insert($wpdb->prefix . 'wpbdp_form_fields', $newfield)) {
|
256 |
+
delete_option('wpbusdirman_postform_field_label_' . $i);
|
257 |
+
delete_option('wpbusdirman_postform_field_type_' . $i);
|
258 |
+
delete_option('wpbusdirman_postform_field_validation_' . $i);
|
259 |
+
delete_option('wpbusdirman_postform_field_association_' . $i);
|
260 |
+
delete_option('wpbusdirman_postform_field_required_' . $i);
|
261 |
+
delete_option('wpbusdirman_postform_field_showinexcerpt_' . $i);
|
262 |
+
delete_option('wpbusdirman_postform_field_hide_' . $i);
|
263 |
+
delete_option('wpbusdirman_postform_field_options_' . $i);
|
264 |
+
delete_option('wpbusdirman_postform_field_order_' . $i);
|
265 |
+
}
|
266 |
+
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
+
public function upgrade_to_2_2() {
|
271 |
+
global $wpdb;
|
272 |
+
$wpdb->query("ALTER TABLE {$wpdb->prefix}wpbdp_form_fields CHARACTER SET utf8 COLLATE utf8_general_ci");
|
273 |
+
$wpdb->query("ALTER TABLE {$wpdb->prefix}wpbdp_form_fields CHANGE `label` `label` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
|
274 |
+
$wpdb->query("ALTER TABLE {$wpdb->prefix}wpbdp_form_fields CHANGE `description` `description` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
|
275 |
+
}
|
276 |
+
|
277 |
+
public function upgrade_to_2_3() {
|
278 |
+
global $wpdb;
|
279 |
+
|
280 |
+
$count = $wpdb->get_var(
|
281 |
+
sprintf("SELECT COUNT(*) FROM {$wpdb->prefix}options WHERE option_name LIKE '%%%s%%'", 'wpbusdirman_settings_fees_label_'));
|
282 |
+
|
283 |
+
for ($i = 1; $i <= $count; $i++) {
|
284 |
+
$label = get_option('_settings_fees_label_' . $i, get_option('wpbusdirman_settings_fees_label_' . $i));
|
285 |
+
$amount = get_option('_settings_fees_amount' . $i, get_option('wpbusdirman_settings_fees_amount_' . $i, '0.00'));
|
286 |
+
$days = intval( get_option('_settings_fees_increment_' . $i, get_option('wpbusdirman_settings_fees_increment_' . $i, 0)) );
|
287 |
+
$images = intval( get_option('_settings_fees_images_' . $i, get_option('wpbusdirman_settings_fees_images_' . $i, 0)) );
|
288 |
+
$categories = get_option('_settings_fees_categories_' . $i, get_option('wpbusdirman_settings_fees_categories_' . $i, ''));
|
289 |
+
|
290 |
+
$newfee = array();
|
291 |
+
$newfee['label'] = $label;
|
292 |
+
$newfee['amount'] = $amount;
|
293 |
+
$newfee['days'] = $days;
|
294 |
+
$newfee['images'] = $images;
|
295 |
+
|
296 |
+
$category_data = array('all' => false, 'categories' => array());
|
297 |
+
if ($categories == '0') {
|
298 |
+
$category_data['all'] = true;
|
299 |
+
} else {
|
300 |
+
foreach (explode(',', $categories) as $category_id) {
|
301 |
+
$category_data['categories'][] = intval($category_id);
|
302 |
+
}
|
303 |
+
}
|
304 |
+
|
305 |
+
$newfee['categories'] = serialize($category_data);
|
306 |
+
|
307 |
+
if ($wpdb->insert($wpdb->prefix . 'wpbdp_fees', $newfee)) {
|
308 |
+
$new_id = $wpdb->insert_id;
|
309 |
+
|
310 |
+
$query = $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value = %s AND {$wpdb->postmeta}.post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = %s)",
|
311 |
+
$new_id, '_wpbdp_listingfeeid', $i, 'wpbdm-directory');
|
312 |
+
$wpdb->query($query);
|
313 |
+
|
314 |
+
foreach (array('label', 'amount', 'increment', 'images', 'categories') as $k) {
|
315 |
+
delete_option('wpbusdirman_settings_fees_' . $k . '_' . $i);
|
316 |
+
delete_option('_settings_fees_' . $k . '_' . $i);
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
public function upgrade_to_2_4() {
|
324 |
+
global $wpdb;
|
325 |
+
global $wpbdp;
|
326 |
+
|
327 |
+
$fields = $wpbdp->formfields->get_fields();
|
328 |
+
|
329 |
+
foreach ($fields as &$field) {
|
330 |
+
$query = $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s AND {$wpdb->postmeta}.post_id IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = %s)",
|
331 |
+
'_wpbdp[fields][' . $field->get_id() . ']', $field->get_label(), 'wpbdm-directory');
|
332 |
+
$wpdb->query($query);
|
333 |
+
}
|
334 |
+
}
|
335 |
+
|
336 |
+
public function upgrade_to_2_5() {
|
337 |
+
global $wpdb;
|
338 |
+
|
339 |
+
wpbdp_log('Updating payment/sticky status values.');
|
340 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", '_wpbdp[sticky]', '_wpbdp_sticky'));
|
341 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value = %s", 'sticky', '_wpbdp[sticky]', 'approved'));
|
342 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value != %s", 'pending', '_wpbdp[sticky]', 'approved'));
|
343 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", '_wpbdp[payment_status]', '_wpbdp_paymentstatus'));
|
344 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND meta_value != %s", 'not-paid', '_wpbdp[payment_status]', 'paid'));
|
345 |
+
|
346 |
+
// Misc updates
|
347 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_totalallowedimages'));
|
348 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_termlength'));
|
349 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_costoflisting'));
|
350 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_listingfeeid'));
|
351 |
+
|
352 |
+
wpbdp_log('Updating listing images to new framework.');
|
353 |
+
|
354 |
+
$old_images = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_image'));
|
355 |
+
foreach ($old_images as $old_image) {
|
356 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
357 |
+
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
358 |
+
|
359 |
+
$filename = ABSPATH . 'wp-content/uploads/wpbdm/' . $old_image->meta_value;
|
360 |
+
|
361 |
+
$wp_filetype = wp_check_filetype(basename($filename), null);
|
362 |
+
|
363 |
+
$attachment_id = wp_insert_attachment(array(
|
364 |
+
'post_mime_type' => $wp_filetype['type'],
|
365 |
+
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
|
366 |
+
'post_content' => '',
|
367 |
+
'post_status' => 'inherit'
|
368 |
+
), $filename, $old_image->post_id);
|
369 |
+
$attach_data = wp_generate_attachment_metadata( $attachment_id, $filename );
|
370 |
+
wp_update_attachment_metadata( $attachment_id, $attach_data );
|
371 |
+
}
|
372 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_image'));
|
373 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp_thumbnail'));
|
374 |
+
}
|
375 |
+
|
376 |
+
public function upgrade_to_3_1() {
|
377 |
+
global $wpdb;
|
378 |
+
|
379 |
+
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s", WPBDP_POST_TYPE, 'wpbdm-directory'));
|
380 |
+
|
381 |
+
if (function_exists('flush_rewrite_rules'))
|
382 |
+
flush_rewrite_rules(false);
|
383 |
+
}
|
384 |
+
|
385 |
+
/*
|
386 |
+
* This update converts all form fields to a new, more flexible format that uses a new API introduced in BD 2.3.
|
387 |
+
*/
|
388 |
+
public function upgrade_to_3_2() {
|
389 |
+
global $wpdb;
|
390 |
+
|
391 |
+
$validators_trans = array(
|
392 |
+
'EmailValidator' => 'email',
|
393 |
+
'URLValidator' => 'url',
|
394 |
+
'IntegerNumberValidator' => 'integer_number',
|
395 |
+
'DecimalNumberValidator' => 'decimal_number',
|
396 |
+
'DateValidator' => 'date_'
|
397 |
+
);
|
398 |
+
|
399 |
+
$old_fields = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wpbdp_form_fields" );
|
400 |
+
|
401 |
+
foreach ( $old_fields as &$f ) {
|
402 |
+
$newfield = array();
|
403 |
+
$newfield['field_type'] = strtolower( $f->type );
|
404 |
+
|
405 |
+
if ( empty( $newfield['field_type'] ) )
|
406 |
+
$newfield['field_type'] = 'textfield';
|
407 |
+
|
408 |
+
$newfield['display_flags'] = array();
|
409 |
+
$newfield['field_data'] = array();
|
410 |
+
$newfield['validators'] = array();
|
411 |
+
|
412 |
+
// display options
|
413 |
+
$f_display_options = array_merge(array('show_in_excerpt' => true, 'show_in_listing' => true, 'show_in_search' => true), $f->display_options ? (array) unserialize($f->display_options) : array());
|
414 |
+
if ( isset( $f_display_options['hide_field'] ) && $f_display_options['hide_field'] ) {
|
415 |
+
// do nothing
|
416 |
+
} else {
|
417 |
+
if ( $f_display_options['show_in_excerpt'] ) $newfield['display_flags'][] = 'excerpt';
|
418 |
+
if ( $f_display_options['show_in_listing'] ) $newfield['display_flags'][] = 'listing';
|
419 |
+
if ( $f_display_options['show_in_search'] ) $newfield['display_flags'][] = 'search';
|
420 |
+
}
|
421 |
+
|
422 |
+
// validators
|
423 |
+
if ( $f->validator && isset( $validators_trans[ $f->validator ] ) ) $newfield['validators'] = array( $validators_trans[ $f->validator ] );
|
424 |
+
if ( $f->is_required ) $newfield['validators'][] = 'required';
|
425 |
+
|
426 |
+
// options for multivalued fields
|
427 |
+
$f_data = $f->field_data ? unserialize( $f->field_data ) : null;
|
428 |
+
$f_data = is_array( $f_data ) ? $f_data : array();
|
429 |
+
|
430 |
+
if ( isset( $f_data['options'] ) && is_array( $f_data['options'] ) ) $newfield['field_data']['options'] = $f_data['options'];
|
431 |
+
if ( isset( $f_data['open_in_new_window'] ) && $f_data['open_in_new_window'] ) $newfield['field_data']['open_in_new_window'] = true;
|
432 |
+
|
433 |
+
if ( $newfield['field_type'] == 'textfield' && in_array( 'url', $newfield['validators']) )
|
434 |
+
$newfield['field_type'] = 'url';
|
435 |
+
|
436 |
+
$newfield['display_flags'] = implode( ',', $newfield['display_flags'] );
|
437 |
+
$newfield['validators'] = implode( ',', $newfield['validators'] );
|
438 |
+
$newfield['field_data'] = serialize( $newfield['field_data'] );
|
439 |
+
|
440 |
+
$wpdb->update( "{$wpdb->prefix}wpbdp_form_fields", $newfield, array( 'id' => $f->id ) );
|
441 |
+
}
|
442 |
+
|
443 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields DROP COLUMN validator;" );
|
444 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields DROP COLUMN display_options;" );
|
445 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields DROP COLUMN is_required;" );
|
446 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields DROP COLUMN type;" );
|
447 |
+
|
448 |
+
add_action( 'admin_notices', array( $this, 'disable_regions_in_3_2_upgrade' ) );
|
449 |
+
}
|
450 |
+
|
451 |
+
public function disable_regions_in_3_2_upgrade() {
|
452 |
+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
453 |
+
|
454 |
+
if ( class_exists( 'WPBDP_RegionsPlugin' ) && version_compare( WPBDP_RegionsPlugin::VERSION, '1.1', '<' ) ) {
|
455 |
+
deactivate_plugins( 'business-directory-regions/business-directory-regions.php', true );
|
456 |
+
echo sprintf( '<div class="error"><p>%s</p></div>',
|
457 |
+
_x( '<b>Business Directory Plugin - Regions Module</b> was disabled because it is incompatible with the current version of Business Directory. Please update the Regions module.', 'installer', 'WPBDM' )
|
458 |
+
);
|
459 |
+
}
|
460 |
+
}
|
461 |
+
|
462 |
+
public function upgrade_to_3_4() {
|
463 |
+
global $wpdb;
|
464 |
+
|
465 |
+
$query = $wpdb->prepare( "UPDATE {$wpdb->prefix}wpbdp_listing_fees SET email_sent = %d WHERE email_sent = %d", 2, 1 );
|
466 |
+
$wpdb->query( $query );
|
467 |
+
}
|
468 |
+
|
469 |
+
public function upgrade_to_3_5() {
|
470 |
+
global $wpdb;
|
471 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->term_taxonomy} SET taxonomy = %s WHERE taxonomy = %s", WPBDP_CATEGORY_TAX, 'wpbdm-category' ) );
|
472 |
+
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->term_taxonomy} SET taxonomy = %s WHERE taxonomy = %s", WPBDP_TAGS_TAX, 'wpbdm-tags' ) );
|
473 |
+
}
|
474 |
+
|
475 |
+
public function upgrade_to_3_6() {
|
476 |
+
global $wpdb;
|
477 |
+
|
478 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_form_fields MODIFY id bigint(20) AUTO_INCREMENT" );
|
479 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_fees MODIFY id bigint(20) AUTO_INCREMENT" );
|
480 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_payments MODIFY id bigint(20) AUTO_INCREMENT" );
|
481 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees MODIFY id bigint(20) AUTO_INCREMENT" );
|
482 |
+
|
483 |
+
update_option(WPBDP_Settings::PREFIX . "listings-per-page", get_option("posts_per_page"));
|
484 |
+
}
|
485 |
+
|
486 |
+
public function upgrade_to_3_7() {
|
487 |
+
global $wpdb;
|
488 |
+
|
489 |
+
// Try to disable incompatible modules.
|
490 |
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
491 |
+
|
492 |
+
if ( is_plugin_active( 'business-directory-regions/business-directory-regions.php' ) ) {
|
493 |
+
deactivate_plugins( 'business-directory-regions/business-directory-regions.php' );
|
494 |
+
}
|
495 |
+
|
496 |
+
// Remove invalid listing fees (quick).
|
497 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id NOT IN (SELECT ID FROM {$wpdb->posts} WHERE post_type = %s)", WPBDP_POST_TYPE ) );
|
498 |
+
$wpdb->query( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE category_id NOT IN (SELECT term_id FROM {$wpdb->terms})" );
|
499 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees DROP charged" );
|
500 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees DROP updated_on" );
|
501 |
+
|
502 |
+
// Update notify-admin email option.
|
503 |
+
if ( get_option( WPBDP_Settings::PREFIX . 'notify-admin', false ) )
|
504 |
+
update_option( WPBDP_Settings::PREFIX . 'admin-notifications', array( 'new-listing') );
|
505 |
+
|
506 |
+
$this->request_manual_upgrade( 'upgrade_to_3_7_migrate_payments' );
|
507 |
+
}
|
508 |
+
|
509 |
+
public function upgrade_to_3_7_migrate_payments() {
|
510 |
+
global $wpdb;
|
511 |
+
|
512 |
+
$status_msg = '';
|
513 |
+
|
514 |
+
// Remove/update listing fees.
|
515 |
+
if ( ! $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->prefix}wpbdp_listing_fees LIKE %s", 'migrated' ) ) )
|
516 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees ADD migrated tinyint(1) DEFAULT 0" );
|
517 |
+
|
518 |
+
$n_fees = intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_listing_fees" ) );
|
519 |
+
$n_fees_migrated = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_listing_fees WHERE migrated = %d", 1 ) ) );
|
520 |
+
$fees_done = ( $n_fees_migrated == $n_fees ) ? true : false;
|
521 |
+
|
522 |
+
if ( ! $fees_done ) {
|
523 |
+
$status_msg = sprintf( _x( 'Cleaning up listing fees information... %d/%d', 'installer', 'WPBDM' ), $n_fees_migrated, $n_fees );
|
524 |
+
|
525 |
+
$fees = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE migrated = %d ORDER BY id ASC LIMIT 50", 0 ), ARRAY_A );
|
526 |
+
|
527 |
+
foreach ( $fees as &$f ) {
|
528 |
+
// Delete fee if category does not exist.
|
529 |
+
if ( ! term_exists( intval( $f['category_id'] ), WPBDP_CATEGORY_TAX ) ) {
|
530 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", $f['id'] ) );
|
531 |
+
} else {
|
532 |
+
// Delete duplicated listing fees.
|
533 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id < %d AND category_id = %d AND listing_id = %d",
|
534 |
+
$f['id'],
|
535 |
+
$f['category_id'],
|
536 |
+
$f['listing_id'] ) );
|
537 |
+
|
538 |
+
$f['fee'] = (array) unserialize( $f['fee'] );
|
539 |
+
$f['fee_days'] = abs( intval( $f['fee']['days'] ) );
|
540 |
+
$f['fee_images'] = abs( intval( $f['fee']['images'] ) );
|
541 |
+
$f['fee_id'] = intval( $f['fee']['id'] );
|
542 |
+
$f['fee'] = '';
|
543 |
+
$f['migrated'] = 1;
|
544 |
+
|
545 |
+
unset( $f['fee'] );
|
546 |
+
|
547 |
+
if ( ! $f['expires_on'] )
|
548 |
+
unset( $f['expires_on'] );
|
549 |
+
|
550 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_listing_fees', $f, array( 'id' => $f['id'] ) );
|
551 |
+
}
|
552 |
+
}
|
553 |
+
}
|
554 |
+
|
555 |
+
// Migrate transactions.
|
556 |
+
$transactions_done = false;
|
557 |
+
|
558 |
+
if ( $fees_done ) {
|
559 |
+
if ( ! $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->prefix}wpbdp_payments LIKE %s", 'migrated' ) ) )
|
560 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_payments ADD migrated tinyint(1) DEFAULT 0" );
|
561 |
+
|
562 |
+
$n_transactions = intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments" ) );
|
563 |
+
$n_transactions_migrated = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}wpbdp_payments WHERE migrated = %d", 1 ) ) );
|
564 |
+
$transactions_done = ( $n_transactions_migrated == $n_transactions ) ? true : false;
|
565 |
+
|
566 |
+
if ( $transactions_done ) {
|
567 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_payments DROP payment_type" );
|
568 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_payments DROP migrated" );
|
569 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees DROP fee" );
|
570 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_listing_fees DROP migrated" );
|
571 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s", '_wpbdp[payment_status]' ) );
|
572 |
+
} else {
|
573 |
+
$status_msg = sprintf( _x( 'Migrating previous transactions to new Payments API... %d/%d', 'installer', 'WPBDM' ), $n_transactions_migrated, $n_transactions );
|
574 |
+
|
575 |
+
$transactions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE migrated = %d ORDER BY id ASC LIMIT 50", 0 ), ARRAY_A );
|
576 |
+
|
577 |
+
foreach ( $transactions as &$t ) {
|
578 |
+
$t['status'] = 'approved' == $t['status'] ? 'completed' : ( 'pending' == $t['status'] ? 'pending' : 'rejected' );
|
579 |
+
$t['currency_code'] = get_option( 'wpbdp-currency' );
|
580 |
+
$t['migrated'] = 1;
|
581 |
+
|
582 |
+
if ( ! isset( $t['processed_on'] ) || empty( $t['processed_on'] ) )
|
583 |
+
unset( $t['processed_on'] );
|
584 |
+
|
585 |
+
if ( ! isset( $t['created_on'] ) || empty( $t['created_on'] ) )
|
586 |
+
unset( $t['created_on'] );
|
587 |
+
|
588 |
+
if ( ! isset( $t['listing_id'] ) || empty( $t['listing_id'] ) )
|
589 |
+
$t['listing_id'] = 0;
|
590 |
+
|
591 |
+
if ( ! isset( $t['amount'] ) || empty( $t['amount'] ) )
|
592 |
+
$t['amount'] = '0.0';
|
593 |
+
|
594 |
+
// TODO: delete duplicated pending transactions (i.e. two renewals for the same category & listing ID that are 'pending').
|
595 |
+
|
596 |
+
switch ( $t['payment_type'] ) {
|
597 |
+
case 'initial':
|
598 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_payments_items',
|
599 |
+
array( 'payment_id' => $t['id'],
|
600 |
+
'amount' => $t['amount'],
|
601 |
+
'item_type' => 'charge',
|
602 |
+
'description' => _x( 'Initial listing payment (BD < 3.4)', 'installer', 'WPBDM' )
|
603 |
+
) );
|
604 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_payments', $t, array( 'id' => $t['id'] ) );
|
605 |
+
|
606 |
+
break;
|
607 |
+
|
608 |
+
case 'edit':
|
609 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_payments_items',
|
610 |
+
array( 'payment_id' => $t['id'],
|
611 |
+
'amount' => $t['amount'],
|
612 |
+
'item_type' => 'charge',
|
613 |
+
'description' => _x( 'Listing edit payment (BD < 3.4)', 'installer', 'WPBDM' )
|
614 |
+
) );
|
615 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_payments', $t, array( 'id' => $t['id'] ) );
|
616 |
+
|
617 |
+
break;
|
618 |
+
|
619 |
+
case 'renewal':
|
620 |
+
$data = unserialize( $t['extra_data'] );
|
621 |
+
$fee_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", $data['renewal_id'] ) );
|
622 |
+
|
623 |
+
if ( ! $fee_info || ! term_exists( intval( $fee_info->category_id ), WPBDP_CATEGORY_TAX ) ) {
|
624 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments WHERE id = %d", $t['id'] ) );
|
625 |
+
continue;
|
626 |
+
}
|
627 |
+
|
628 |
+
$fee_info->fee = unserialize( $fee_info->fee );
|
629 |
+
|
630 |
+
$item = array();
|
631 |
+
$item['payment_id'] = $t['id'];
|
632 |
+
$item['amount'] = $t['amount'];
|
633 |
+
$item['item_type'] = 'fee';
|
634 |
+
$item['description'] = sprintf( _x( 'Renewal fee "%s" for category "%s"', 'installer', 'WPBDM' ),
|
635 |
+
$fee_info->fee['label'],
|
636 |
+
wpbdp_get_term_name( $fee_info->category_id ) );
|
637 |
+
$item['data'] = serialize( array( 'fee' => $fee_info->fee ) );
|
638 |
+
$item['rel_id_1'] = $fee_info->category_id;
|
639 |
+
$item['rel_id_2'] = $fee_info->fee['id'];
|
640 |
+
|
641 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_payments_items', $item );
|
642 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_payments', $t, array( 'id' => $t['id'] ) );
|
643 |
+
|
644 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", $data['renewal_id'] ) );
|
645 |
+
|
646 |
+
break;
|
647 |
+
|
648 |
+
case 'upgrade-to-sticky':
|
649 |
+
$wpdb->insert( $wpdb->prefix . 'wpbdp_payments_items',
|
650 |
+
array( 'payment_id' => $t['id'],
|
651 |
+
'amount' => $t['amount'],
|
652 |
+
'item_type' => 'upgrade',
|
653 |
+
'description' => _x( 'Listing upgrade to featured', 'installer', 'WPBDM' )
|
654 |
+
) );
|
655 |
+
$wpdb->update( $wpdb->prefix . 'wpbdp_payments', $t, array( 'id' => $t['id'] ) );
|
656 |
+
|
657 |
+
break;
|
658 |
+
|
659 |
+
default:
|
660 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wpbdp_payments WHERE id = %d", $t['id'] ) );
|
661 |
+
break;
|
662 |
+
}
|
663 |
+
|
664 |
+
}
|
665 |
+
}
|
666 |
+
}
|
667 |
+
|
668 |
+
$res = array( 'ok' => true,
|
669 |
+
'done' => $transactions_done,
|
670 |
+
'status' => $status_msg );
|
671 |
+
|
672 |
+
return $res;
|
673 |
+
}
|
674 |
+
|
675 |
+
public function upgrade_to_3_9() {
|
676 |
+
// TODO: make sure this works when passing through manual 3.7 upgrade.
|
677 |
+
global $wpdb;
|
678 |
+
|
679 |
+
if ( $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->prefix}wpbdp_submit_state LIKE %s", 'created' ) ) )
|
680 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_submit_state DROP COLUMN created" );
|
681 |
+
|
682 |
+
if ( $wpdb->get_col( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->prefix}wpbdp_submit_state LIKE %s", 'updated' ) ) ) {
|
683 |
+
$wpdb->query( "UPDATE {$wpdb->prefix}wpbdp_submit_state SET updated_on = updated" );
|
684 |
+
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wpbdp_submit_state DROP COLUMN updated" );
|
685 |
+
}
|
686 |
+
}
|
687 |
+
|
688 |
+
public function upgrade_to_4_0() {
|
689 |
+
$o = (bool) get_option( WPBDP_Settings::PREFIX . 'send-email-confirmation', false );
|
690 |
+
|
691 |
+
if ( ! $o ) {
|
692 |
+
update_option( WPBDP_Settings::PREFIX . 'user-notifications', array( 'listing-published' ) );
|
693 |
+
}
|
694 |
+
delete_option( WPBDP_Settings::PREFIX . 'send-email-confirmation' );
|
695 |
+
|
696 |
+
}
|
697 |
+
|
698 |
+
}
|
699 |
+
|
700 |
+
class WPBDP_Installer_Manual_Upgrade {
|
701 |
+
|
702 |
+
private $installer;
|
703 |
+
private $callback;
|
704 |
+
|
705 |
+
public function __construct( &$installer, $callback ) {
|
706 |
+
add_action( 'admin_notices', array( &$this, 'upgrade_required_notice' ) );
|
707 |
+
add_action( 'admin_menu', array( &$this, 'add_upgrade_page' ) );
|
708 |
+
add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
|
709 |
+
add_action( 'wp_ajax_wpbdp-manual-upgrade', array( &$this, 'handle_ajax' ) );
|
710 |
+
|
711 |
+
$this->installer = $installer;
|
712 |
+
$this->callback = $callback;
|
713 |
+
}
|
714 |
+
|
715 |
+
public function upgrade_required_notice() {
|
716 |
+
global $pagenow;
|
717 |
+
|
718 |
+
if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'wpbdp-upgrade-page' == $_GET['page'] )
|
719 |
+
return;
|
720 |
+
|
721 |
+
print '<div class="error"><p>';
|
722 |
+
print '<strong>' . __( 'Business Directory - Manual Upgrade Required', 'WPBDM' ) . '</strong>';
|
723 |
+
print '<br />';
|
724 |
+
_e( 'Business Directory features are currently disabled because the plugin needs to perform a manual upgrade before continuing.', 'WPBDM' );
|
725 |
+
print '<br /><br />';
|
726 |
+
printf( '<a class="button button-primary" href="%s">%s</a>', admin_url( 'admin.php?page=wpbdp-upgrade-page' ), __( 'Perform Manual Upgrade', 'WPBDM' ) );
|
727 |
+
print '</p></div>';
|
728 |
+
}
|
729 |
+
|
730 |
+
public function add_upgrade_page() {
|
731 |
+
global $submenu;
|
732 |
+
|
733 |
+
// Make "Directory" menu items point to upgrade page.
|
734 |
+
$menu_id = 'edit.php?post_type=' . WPBDP_POST_TYPE;
|
735 |
+
if ( isset( $submenu[ $menu_id ] ) ) {
|
736 |
+
foreach ( $submenu[ $menu_id ] as &$item ) {
|
737 |
+
$item[2] = admin_url( 'admin.php?page=wpbdp-upgrade-page' );
|
738 |
+
}
|
739 |
+
}
|
740 |
+
|
741 |
+
add_submenu_page( 'options.php',
|
742 |
+
__( 'Business Directory - Manual Upgrade', 'WPBDM' ),
|
743 |
+
__( 'Business Directory - Manual Upgrade', 'WPBDM' ),
|
744 |
+
'administrator',
|
745 |
+
'wpbdp-upgrade-page',
|
746 |
+
array( &$this, 'upgrade_page' ) );
|
747 |
+
}
|
748 |
+
|
749 |
+
public function enqueue_scripts() {
|
750 |
+
wp_enqueue_script( 'wpbdp-manual-upgrade' , WPBDP_URL . 'admin/resources/manual-upgrade.js' );
|
751 |
+
}
|
752 |
+
|
753 |
+
public function upgrade_page() {
|
754 |
+
echo wpbdp_admin_header( __( 'Business Directory - Manual Upgrade', 'WPBDM' ), 'manual-upgrade', null, false );
|
755 |
+
|
756 |
+
echo '<div class="step-upgrade">';
|
757 |
+
echo '<p>';
|
758 |
+
_e( 'Business Directory features are currently disabled because the plugin needs to perform a manual upgrade before it can be used.', 'WPBDM' );
|
759 |
+
echo '<br />';
|
760 |
+
_e( 'Click "Start Upgrade" and wait until the process finishes.', 'WPBDM' );
|
761 |
+
echo '</p>';
|
762 |
+
echo '<p>';
|
763 |
+
echo '<a href="#" class="start-upgrade button button-primary">' . _x( 'Start Upgrade', 'manual-upgrade', 'WPBDM' ) . '</a>';
|
764 |
+
echo ' ';
|
765 |
+
echo '<a href="#" class="pause-upgrade button">' . _x( 'Pause Upgrade', 'manual-upgrade', 'WPBDM' ) . '</a>';
|
766 |
+
echo '</p>';
|
767 |
+
echo '<textarea id="manual-upgrade-progress" rows="20" style="width: 90%; font-family: courier, monospaced; font-size: 12px;" readonly="readonly"></textarea>';
|
768 |
+
echo '</div>';
|
769 |
+
|
770 |
+
echo '<div class="step-done" style="display: none;">';
|
771 |
+
echo '<p>' . _x( 'The upgrade was sucessfully performed. Business Directory Plugin is now available.', 'manual-upgrade', 'WPBDM' ) . '</p>';
|
772 |
+
printf ( '<a href="%s" class="button button-primary">%s</a>',
|
773 |
+
admin_url( 'admin.php?page=wpbdp_admin' ),
|
774 |
+
_x( 'Go to "Directory Admin"', 'manual-upgrade', 'WPBDM' ) );
|
775 |
+
echo '</div>';
|
776 |
+
|
777 |
+
echo wpbdp_admin_footer();
|
778 |
+
}
|
779 |
+
|
780 |
+
public function handle_ajax() {
|
781 |
+
// if ( ! current_user_can( 'administrator' ) || ! isset( $_POST['action'] ) )
|
782 |
+
// return;
|
783 |
+
|
784 |
+
$response = call_user_func( array( $this->installer, $this->callback ) );
|
785 |
+
|
786 |
+
print json_encode( $response );
|
787 |
+
|
788 |
+
if ( $response['done'] )
|
789 |
+
delete_option( 'wpbdp-manual-upgrade-pending' );
|
790 |
+
|
791 |
+
exit();
|
792 |
+
}
|
793 |
+
|
794 |
+
}
|
core/js/debug.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(function($) {
|
2 |
+
|
3 |
+
var $wpbdp_debugging = $('#wpbdp-debugging');
|
4 |
+
var $tab_selector = $('.tab-selector', $wpbdp_debugging);
|
5 |
+
|
6 |
+
$('#wpbody .wrap').before('<div id="wpbdp-debugging-placeholder"></div>');
|
7 |
+
$('#wpbdp-debugging-placeholder').replaceWith($('#wpbdp-debugging'));
|
8 |
+
|
9 |
+
$tab_selector.find('li a').click(function(e) {
|
10 |
+
e.preventDefault();
|
11 |
+
|
12 |
+
var dest = '#wpbdp-debugging-tab-' + $(this).attr('href').replace('#', '');
|
13 |
+
|
14 |
+
$tab_selector.find('li').removeClass('active');
|
15 |
+
$(this).parent('li').addClass('active');
|
16 |
+
$wpbdp_debugging.find('.tab').hide();
|
17 |
+
$(dest).show();
|
18 |
+
}).first().click();
|
19 |
+
|
20 |
+
$wpbdp_debugging.find('table tr').click(function(e) {
|
21 |
+
var $extradata = $(this).find('.extradata');
|
22 |
+
|
23 |
+
if ( $extradata.length > 0 )
|
24 |
+
$extradata.toggle();
|
25 |
+
});
|
26 |
+
|
27 |
+
});
|
core/js/debug.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jQuery(function($){var $wpbdp_debugging=$("#wpbdp-debugging");var $tab_selector=$(".tab-selector",$wpbdp_debugging);$("#wpbody .wrap").before('<div id="wpbdp-debugging-placeholder"></div>');$("#wpbdp-debugging-placeholder").replaceWith($("#wpbdp-debugging"));$tab_selector.find("li a").click(function(e){e.preventDefault();var dest="#wpbdp-debugging-tab-"+$(this).attr("href").replace("#","");$tab_selector.find("li").removeClass("active");$(this).parent("li").addClass("active");$wpbdp_debugging.find(".tab").hide();$(dest).show()}).first().click();$wpbdp_debugging.find("table tr").click(function(e){var $extradata=$(this).find(".extradata");if($extradata.length>0){$extradata.toggle()}})});
|
core/js/dnd-upload.js
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var wpbdp = window.wpbdp || {};
|
2 |
+
|
3 |
+
( function( $ ) {
|
4 |
+
var dnd = wpbdp.dnd = {
|
5 |
+
setup: function( $area, options ) {
|
6 |
+
var options = $.extend( options, {} );
|
7 |
+
var $input = $area.find( 'input[type="file"]' );
|
8 |
+
|
9 |
+
$area.data( 'dnd-working', false );
|
10 |
+
$area.on( 'dragover',
|
11 |
+
function( e ) {
|
12 |
+
if ( ! $( this ).hasClass( 'dragging' ) )
|
13 |
+
$( this ).addClass( 'dragging' );
|
14 |
+
} )
|
15 |
+
.on( 'dragleave',
|
16 |
+
function( e ) {
|
17 |
+
if ( $( this ).hasClass('dragging') )
|
18 |
+
$( this ).removeClass( 'dragging' );
|
19 |
+
} );
|
20 |
+
$input.fileupload({
|
21 |
+
url: $area.attr( 'data-action' ) ? $area.attr( 'data-action' ) : options.url,
|
22 |
+
sequentialUploads: true,
|
23 |
+
dataType: 'json',
|
24 |
+
singleFileUploads: false,
|
25 |
+
dropZone: $area,
|
26 |
+
formData: function( form ) {
|
27 |
+
return [ { name: 'dummy', value: 1 } ];
|
28 |
+
},
|
29 |
+
send: function( e, data ) {
|
30 |
+
if ( $area.data('dnd-working' ) )
|
31 |
+
return false;
|
32 |
+
|
33 |
+
if ( 'undefined' !== typeof options.validate )
|
34 |
+
if ( ! options.validate.call( $area, data ) )
|
35 |
+
return false;
|
36 |
+
|
37 |
+
$area.removeClass( 'dragging' );
|
38 |
+
$area.removeClass( 'error' );
|
39 |
+
$area.data( 'dnd-working', true );
|
40 |
+
|
41 |
+
$area.find( '.dnd-area-inside' ).fadeOut( 'fast', function() {
|
42 |
+
// TODO: use some text-based options instead of requiring additional <div>s inside $area.
|
43 |
+
$area.find( '.dnd-area-inside-working span' ).text( data.files.length );
|
44 |
+
$area.find( '.dnd-area-inside-working' ).fadeIn( 'fast' );
|
45 |
+
} );
|
46 |
+
|
47 |
+
return true;
|
48 |
+
},
|
49 |
+
done: function( e, data ) {
|
50 |
+
var res = data.result;
|
51 |
+
|
52 |
+
if ( ! res.success )
|
53 |
+
return;
|
54 |
+
|
55 |
+
$area.data( 'dnd-working', false );
|
56 |
+
$area.find( '.dnd-area-inside-working' ).hide();
|
57 |
+
$area.find( '.dnd-area-inside' ).fadeIn( 'fast' );
|
58 |
+
|
59 |
+
if ( 'undefined' !== typeof options.done )
|
60 |
+
options.done.call( $area, res );
|
61 |
+
}
|
62 |
+
});
|
63 |
+
|
64 |
+
if ( 'undefined' !== typeof options.init ) {
|
65 |
+
options.init.call( $area );
|
66 |
+
}
|
67 |
+
}
|
68 |
+
};
|
69 |
+
|
70 |
+
} )( jQuery );
|
core/js/dnd-upload.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
var wpbdp=window.wpbdp||{};(function($){var dnd=wpbdp.dnd={setup:function($area,options){var options=$.extend(options,{});var $input=$area.find('input[type="file"]');$area.data("dnd-working",false);$area.on("dragover",function(e){if(!$(this).hasClass("dragging")){$(this).addClass("dragging")}}).on("dragleave",function(e){if($(this).hasClass("dragging")){$(this).removeClass("dragging")}});$input.fileupload({url:$area.attr("data-action")?$area.attr("data-action"):options.url,sequentialUploads:true,dataType:"json",singleFileUploads:false,dropZone:$area,formData:function(form){return[{name:"dummy",value:1}]},send:function(e,data){if($area.data("dnd-working")){return false}if("undefined"!==typeof options.validate){if(!options.validate.call($area,data)){return false}}$area.removeClass("dragging");$area.removeClass("error");$area.data("dnd-working",true);$area.find(".dnd-area-inside").fadeOut("fast",function(){$area.find(".dnd-area-inside-working span").text(data.files.length);$area.find(".dnd-area-inside-working").fadeIn("fast")});return true},done:function(e,data){var res=data.result;if(!res.success){return}$area.data("dnd-working",false);$area.find(".dnd-area-inside-working").hide();$area.find(".dnd-area-inside").fadeIn("fast");if("undefined"!==typeof options.done){options.done.call($area,res)}}});if("undefined"!==typeof options.init){options.init.call($area)}}}})(jQuery);
|
core/js/googlewallet.js
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
jQuery(function($) {
|
3 |
+
$('#googlewallet-buy').click(function(e) {
|
4 |
+
e.preventDefault();
|
5 |
+
|
6 |
+
var $context = $(this).parents('form');
|
7 |
+
|
8 |
+
google.payments.inapp.buy({
|
9 |
+
"jwt": $context.find('input[name="jwt"]').val(),
|
10 |
+
|
11 |
+
"success": function(result) {
|
12 |
+
$context.find('input[name="order_id"]').val(result.response.orderId);
|
13 |
+
$context.find('input[name="jwt"]').val(result.jwt);
|
14 |
+
$context.submit();
|
15 |
+
},
|
16 |
+
|
17 |
+
"failure": function(result) {
|
18 |
+
$context.find('input[name="success"]').val('0');
|
19 |
+
$context.find('input[name="error"]').val(result.response.errorType);
|
20 |
+
$context.submit();
|
21 |
+
}
|
22 |
+
});
|
23 |
+
});
|
24 |
+
});
|
core/js/googlewallet.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jQuery(function($){$("#googlewallet-buy").click(function(e){e.preventDefault();var $context=$(this).parents("form");google.payments.inapp.buy({jwt:$context.find('input[name="jwt"]').val(),success:function(result){$context.find('input[name="order_id"]').val(result.response.orderId);$context.find('input[name="jwt"]').val(result.jwt);$context.submit()},failure:function(result){$context.find('input[name="success"]').val("0");$context.find('input[name="error"]').val(result.response.errorType);$context.submit()}})})});
|
core/js/wpbdp.js
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
if (typeof(window.WPBDP) == 'undefined') {
|
2 |
+
window.WPBDP = {};
|
3 |
+
}
|
4 |
+
|
5 |
+
if (typeof(window.wpbdp) == 'undefined') {
|
6 |
+
window.wpbdp = {};
|
7 |
+
}
|
8 |
+
|
9 |
+
jQuery(document).ready(function($){
|
10 |
+
|
11 |
+
if ( $('.wpbdp-bar').children().length == 0 && $.trim( $('.wpbdp-bar').text() ) == '' ) {
|
12 |
+
$('.wpbdp-bar').remove();
|
13 |
+
}
|
14 |
+
|
15 |
+
});
|
16 |
+
|
17 |
+
WPBDP.fileUpload = {
|
18 |
+
|
19 |
+
resizeIFrame: function(field_id, height) {
|
20 |
+
var iframe = jQuery( '#wpbdp-upload-iframe-' + field_id )[0];
|
21 |
+
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
|
22 |
+
|
23 |
+
if ( iframeWin.document.body ) {
|
24 |
+
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
|
25 |
+
}
|
26 |
+
},
|
27 |
+
|
28 |
+
handleUpload: function(o) {
|
29 |
+
var $input = jQuery(o);
|
30 |
+
var $form = $input.parent('form');
|
31 |
+
|
32 |
+
$form.submit();
|
33 |
+
},
|
34 |
+
|
35 |
+
finishUpload: function(field_id, upload_id) {
|
36 |
+
var $iframe = jQuery('#wpbdp-upload-iframe-' + field_id);
|
37 |
+
// $iframe.contents().find('form').hide();
|
38 |
+
|
39 |
+
var $input = jQuery('input[name="listingfields[' + field_id + ']"]');
|
40 |
+
$input.val(upload_id);
|
41 |
+
|
42 |
+
var $preview = $input.siblings('.preview');
|
43 |
+
$preview.find('img').remove();
|
44 |
+
$preview.prepend($iframe.contents().find('.preview').html());
|
45 |
+
$iframe.contents().find('.preview').remove();
|
46 |
+
|
47 |
+
$preview.find('.delete').show();
|
48 |
+
},
|
49 |
+
|
50 |
+
deleteUpload: function(field_id) {
|
51 |
+
var $input = jQuery('input[name="listingfields[' + field_id + ']"]');
|
52 |
+
var $preview = $input.siblings('.preview');
|
53 |
+
|
54 |
+
$input.val('');
|
55 |
+
$preview.find('img').remove();
|
56 |
+
|
57 |
+
$preview.find('.delete').hide();
|
58 |
+
|
59 |
+
return false;
|
60 |
+
}
|
61 |
+
|
62 |
+
};
|
63 |
+
|
64 |
+
|
65 |
+
// {{ Listing submit process.
|
66 |
+
( function( $ ) {
|
67 |
+
var sb = wpbdp.listingSubmit = {
|
68 |
+
init: function() {
|
69 |
+
if ( $( '.wpbdp-submit-page.step-fee-selection' ).length > 0 ) {
|
70 |
+
$( '#wpbdp-listing-form-fees .fee-selection input' ).change(function( e ) {
|
71 |
+
console.log(this);
|
72 |
+
if ( 1 == $( this ).attr( 'data-canrecur' ) ) {
|
73 |
+
if ( $( '.make-charges-recurring-option' ).not( ':visible' ) )
|
74 |
+
$( '.make-charges-recurring-option' ).fadeIn( 'fast' );
|
75 |
+
} else {
|
76 |
+
$( '.make-charges-recurring-option' ).fadeOut( 'fast' );
|
77 |
+
}
|
78 |
+
}).filter( ':checked' ).trigger( 'change' );
|
79 |
+
}
|
80 |
+
|
81 |
+
if ( $( '.wpbdp-submit-page.step-images' ).length > 0 )
|
82 |
+
sb.images.init();
|
83 |
+
}
|
84 |
+
};
|
85 |
+
|
86 |
+
var sbImages = sb.images = wpbdp.listingSubmit.images = {
|
87 |
+
_slots: 0,
|
88 |
+
_slotsRemaining: 0,
|
89 |
+
_working: false,
|
90 |
+
|
91 |
+
init: function() {
|
92 |
+
var t = this;
|
93 |
+
|
94 |
+
// Initialize slot quantities.
|
95 |
+
sb.images._slots = parseInt( $( '#image-slots-total' ).text() );
|
96 |
+
sb.images._slotsRemaining = parseInt( $( '#image-slots-remaining' ).text() );
|
97 |
+
|
98 |
+
// Handle image deletes.
|
99 |
+
$( '#wpbdp-uploaded-images' ).delegate( '.delete-image', 'click', function( e ) {
|
100 |
+
e.preventDefault();
|
101 |
+
var url = $( this ).attr('data-action');
|
102 |
+
|
103 |
+
$.post( url, { 'state': $( 'form#wpbdp-listing-form-images input[name="_state"]' ).val() }, function( res ) {
|
104 |
+
if ( ! res.success )
|
105 |
+
return;
|
106 |
+
|
107 |
+
$( '#wpbdp-uploaded-images .wpbdp-image[data-imageid="' + res.data.imageId + '"]' ).fadeOut( function() {
|
108 |
+
$( this ).remove();
|
109 |
+
|
110 |
+
t._slotsRemaining++;
|
111 |
+
$( '#image-slots-remaining' ).text( t._slotsRemaining );
|
112 |
+
|
113 |
+
if ( t._slotsRemaining == t._slots )
|
114 |
+
$( '#no-images-message' ).show();
|
115 |
+
|
116 |
+
if ( t._slotsRemaining > 0 ) {
|
117 |
+
$( '#image-upload-dnd-area .dnd-area-inside' ).show();
|
118 |
+
$( '#noslots-message' ).hide();
|
119 |
+
$( '#image-upload-dnd-area' ).removeClass('error');
|
120 |
+
$( '#image-upload-dnd-area .dnd-area-inside-error' ).hide();
|
121 |
+
}
|
122 |
+
|
123 |
+
} );
|
124 |
+
}, 'json' );
|
125 |
+
} );
|
126 |
+
|
127 |
+
wpbdp.dnd.setup( $( '#image-upload-dnd-area' ), {
|
128 |
+
init: function() {
|
129 |
+
if ( t._slotsRemaining > 0 )
|
130 |
+
return;
|
131 |
+
|
132 |
+
$( '#image-upload-dnd-area .dnd-area-inside' ).hide();
|
133 |
+
$( '#noslots-message' ).show();
|
134 |
+
$( '#image-upload-dnd-area' ).addClass('error');
|
135 |
+
$( '#image-upload-dnd-area .dnd-area-inside-error' ).show();
|
136 |
+
},
|
137 |
+
validate: function( data ) {
|
138 |
+
$( this ).siblings( '.wpbdp-msg' ).remove();
|
139 |
+
return ( t._slotsRemaining - data.files.length ) >= 0;
|
140 |
+
},
|
141 |
+
done: function( res ) {
|
142 |
+
$( '#no-images-message' ).hide();
|
143 |
+
$( '#wpbdp-uploaded-images' ).append( res.data.html );
|
144 |
+
|
145 |
+
t._slotsRemaining -= res.data.attachmentIds.length;
|
146 |
+
$( '#image-slots-remaining' ).text( t._slotsRemaining );
|
147 |
+
|
148 |
+
if ( 0 == t._slotsRemaining ) {
|
149 |
+
$( '#image-upload-dnd-area .dnd-area-inside' ).hide();
|
150 |
+
$( '#noslots-message' ).show();
|
151 |
+
$( '#image-upload-dnd-area' ).addClass('error');
|
152 |
+
$( '#image-upload-dnd-area .dnd-area-inside' ).hide();
|
153 |
+
$( '#image-upload-dnd-area .dnd-area-inside-error' ).show();
|
154 |
+
} else if ( 'undefined' !== typeof res.data.uploadErrors ) {
|
155 |
+
var errorMsg = $( '<div>' ).addClass('wpbdp-msg error').html( res.data.uploadErrors );
|
156 |
+
$( '.area-and-conditions' ).prepend( errorMsg );
|
157 |
+
}
|
158 |
+
}
|
159 |
+
} );
|
160 |
+
},
|
161 |
+
};
|
162 |
+
|
163 |
+
$( document ).ready( function() {
|
164 |
+
if ( 0 == $( '.wpbdp-submit-page' ).length )
|
165 |
+
return;
|
166 |
+
|
167 |
+
sb.init();
|
168 |
+
} );
|
169 |
+
} )( jQuery );
|
170 |
+
|
171 |
+
// }}
|
core/js/wpbdp.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
if(typeof(window.WPBDP)=="undefined"){window.WPBDP={}}if(typeof(window.wpbdp)=="undefined"){window.wpbdp={}}jQuery(document).ready(function($){if($(".wpbdp-bar").children().length==0&&$.trim($(".wpbdp-bar").text())==""){$(".wpbdp-bar").remove()}});WPBDP.fileUpload={resizeIFrame:function(field_id,height){var iframe=jQuery("#wpbdp-upload-iframe-"+field_id)[0];var iframeWin=iframe.contentWindow||iframe.contentDocument.parentWindow;if(iframeWin.document.body){iframe.height=iframeWin.document.documentElement.scrollHeight||iframeWin.document.body.scrollHeight}},handleUpload:function(o){var $input=jQuery(o);var $form=$input.parent("form");$form.submit()},finishUpload:function(field_id,upload_id){var $iframe=jQuery("#wpbdp-upload-iframe-"+field_id);var $input=jQuery('input[name="listingfields['+field_id+']"]');$input.val(upload_id);var $preview=$input.siblings(".preview");$preview.find("img").remove();$preview.prepend($iframe.contents().find(".preview").html());$iframe.contents().find(".preview").remove();$preview.find(".delete").show()},deleteUpload:function(field_id){var $input=jQuery('input[name="listingfields['+field_id+']"]');var $preview=$input.siblings(".preview");$input.val("");$preview.find("img").remove();$preview.find(".delete").hide();return false}};(function($){var sb=wpbdp.listingSubmit={init:function(){if($(".wpbdp-submit-page.step-fee-selection").length>0){$("#wpbdp-listing-form-fees .fee-selection input").change(function(e){console.log(this);if(1==$(this).attr("data-canrecur")){if($(".make-charges-recurring-option").not(":visible")){$(".make-charges-recurring-option").fadeIn("fast")}}else{$(".make-charges-recurring-option").fadeOut("fast")}}).filter(":checked").trigger("change")}if($(".wpbdp-submit-page.step-images").length>0){sb.images.init()}}};var sbImages=sb.images=wpbdp.listingSubmit.images={_slots:0,_slotsRemaining:0,_working:false,init:function(){var t=this;sb.images._slots=parseInt($("#image-slots-total").text());sb.images._slotsRemaining=parseInt($("#image-slots-remaining").text());$("#wpbdp-uploaded-images").delegate(".delete-image","click",function(e){e.preventDefault();var url=$(this).attr("data-action");$.post(url,{state:$('form#wpbdp-listing-form-images input[name="_state"]').val()},function(res){if(!res.success){return}$('#wpbdp-uploaded-images .wpbdp-image[data-imageid="'+res.data.imageId+'"]').fadeOut(function(){$(this).remove();t._slotsRemaining++;$("#image-slots-remaining").text(t._slotsRemaining);if(t._slotsRemaining==t._slots){$("#no-images-message").show()}if(t._slotsRemaining>0){$("#image-upload-dnd-area .dnd-area-inside").show();$("#noslots-message").hide();$("#image-upload-dnd-area").removeClass("error");$("#image-upload-dnd-area .dnd-area-inside-error").hide()}})},"json")});wpbdp.dnd.setup($("#image-upload-dnd-area"),{init:function(){if(t._slotsRemaining>0){return}$("#image-upload-dnd-area .dnd-area-inside").hide();$("#noslots-message").show();$("#image-upload-dnd-area").addClass("error");$("#image-upload-dnd-area .dnd-area-inside-error").show()},validate:function(data){$(this).siblings(".wpbdp-msg").remove();return(t._slotsRemaining-data.files.length)>=0},done:function(res){$("#no-images-message").hide();$("#wpbdp-uploaded-images").append(res.data.html);t._slotsRemaining-=res.data.attachmentIds.length;$("#image-slots-remaining").text(t._slotsRemaining);if(0==t._slotsRemaining){$("#image-upload-dnd-area .dnd-area-inside").hide();$("#noslots-message").show();$("#image-upload-dnd-area").addClass("error");$("#image-upload-dnd-area .dnd-area-inside").hide();$("#image-upload-dnd-area .dnd-area-inside-error").show()}else{if("undefined"!==typeof res.data.uploadErrors){var errorMsg=$("<div>").addClass("wpbdp-msg error").html(res.data.uploadErrors);$(".area-and-conditions").prepend(errorMsg)}}}})}};$(document).ready(function(){if(0==$(".wpbdp-submit-page").length){return}sb.init()})})(jQuery);
|
core/licensing.php
ADDED
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//set_site_transient( 'update_plugins', null );
|
3 |
+
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @since 3.4.2
|
7 |
+
*/
|
8 |
+
class WPBDP_Licensing {
|
9 |
+
|
10 |
+
const STORE_URL = 'http://businessdirectoryplugin.com/';
|
11 |
+
//const STORE_URL = 'http://192.168.13.37/';
|
12 |
+
|
13 |
+
private $modules = array();
|
14 |
+
|
15 |
+
public function __construct() {
|
16 |
+
add_action( 'admin_init', array( &$this, 'admin_init' ), 0 );
|
17 |
+
add_action( 'admin_notices', array( &$this, 'admin_notices' ) );
|
18 |
+
add_action( 'wpbdp_register_settings', array( &$this, 'register_settings' ) );
|
19 |
+
add_action( 'wpbdp_admin_menu', array( &$this, 'admin_menu' ) );
|
20 |
+
|
21 |
+
add_action( 'wp_ajax_wpbdp-activate-license', array( &$this, 'ajax_activate_license' ) );
|
22 |
+
add_action( 'wp_ajax_wpbdp-deactivate-license', array( &$this, 'ajax_deactivate_license' ) );
|
23 |
+
add_action( 'wp_ajax_wpbdp-license-expired-warning-dismiss', array( &$this, 'ajax_dismiss_license_warning' ) );
|
24 |
+
|
25 |
+
add_action( 'wpbdp_license_check', array( &$this, 'license_check' ) );
|
26 |
+
|
27 |
+
add_filter( 'wpbdp_settings_group_tab_css', array( &$this, 'licenses_tab_css' ), 10, 2 );
|
28 |
+
|
29 |
+
if ( ! wp_next_scheduled( 'wpbdp_license_check' ) ) {
|
30 |
+
wp_schedule_event( time(), 'daily', 'wpbdp_license_check' );
|
31 |
+
}
|
32 |
+
|
33 |
+
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
|
34 |
+
require_once ( WPBDP_PATH . 'vendors/edd/EDD_SL_Plugin_Updater.php' );
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
function register_settings( &$settings ) {
|
39 |
+
if ( ! $this->modules )
|
40 |
+
return;
|
41 |
+
|
42 |
+
$g = $settings->add_group( 'licenses',
|
43 |
+
_x( 'Licenses', 'settings', 'WPBDM' ) );
|
44 |
+
$s = $settings->add_section( $g,
|
45 |
+
'licenses/keys',
|
46 |
+
_x( 'Premium Modules', 'settings', 'WPBDM' ) );
|
47 |
+
|
48 |
+
foreach ( $this->modules as $id => $data ) {
|
49 |
+
$settings->add_setting( $s,
|
50 |
+
'license-key-' . $id,
|
51 |
+
$data['name'],
|
52 |
+
'license_key',
|
53 |
+
'',
|
54 |
+
'',
|
55 |
+
null,
|
56 |
+
array( &$this, '_validate_license_setting' ) );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
function admin_menu( $menu ) {
|
61 |
+
if ( ! current_user_can( 'administrator' ) || ! $this->modules )
|
62 |
+
return;
|
63 |
+
|
64 |
+
add_submenu_page( 'wpbdp_admin',
|
65 |
+
_x( 'Licenses', 'settings', 'WPBDM' ),
|
66 |
+
_x( 'Licenses', 'settings', 'WPBDM' ),
|
67 |
+
'administrator',
|
68 |
+
'wpbdp-licenses',
|
69 |
+
'__return_false' );
|
70 |
+
global $submenu;
|
71 |
+
|
72 |
+
foreach ( $submenu as $menu_id => &$m ) {
|
73 |
+
if ( $menu == $menu_id ) {
|
74 |
+
foreach ( $m as &$i ) {
|
75 |
+
if ( 'wpbdp-licenses' == $i[2] ) {
|
76 |
+
$i[2] = admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=licenses' );
|
77 |
+
break;
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
break;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
function _validate_license_setting( $setting, $new_value = '', $old_value = '' ) {
|
87 |
+
$module = str_replace( 'license-key-', '', $setting->name );
|
88 |
+
|
89 |
+
if ( $new_value !== $old_value )
|
90 |
+
delete_option( 'wpbdp-license-status-' . $module );
|
91 |
+
|
92 |
+
return $new_value;
|
93 |
+
}
|
94 |
+
|
95 |
+
function licenses_tab_css( $css = '', $group ) {
|
96 |
+
if ( 'licenses' !== $group->slug )
|
97 |
+
return $css;
|
98 |
+
|
99 |
+
foreach ( $this->modules as $module => $data ) {
|
100 |
+
if ( 'valid' != $data['license_status'] )
|
101 |
+
return $css . ' group-error';
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
function activate_license( $module ) {
|
106 |
+
if ( ! in_array( $module, array_keys( $this->modules ), true ) )
|
107 |
+
return new WP_Error( 'invalid-module', _x( 'Invalid module ID', 'licensing', 'WPBDM' ), $module );
|
108 |
+
|
109 |
+
$key = trim( get_option( 'wpbdp-license-key-' . $module, '' ) );
|
110 |
+
|
111 |
+
if ( ! $key )
|
112 |
+
return new WP_Error( 'no-license-provided', _x( 'No license key provided', 'licensing', 'WPBDM' ) );
|
113 |
+
|
114 |
+
$module_data = $this->modules[ $module ];
|
115 |
+
|
116 |
+
$request = array(
|
117 |
+
'edd_action' => 'activate_license',
|
118 |
+
'license' => $key,
|
119 |
+
'item_name' => urlencode( $module_data['name'] ),
|
120 |
+
'url' => home_url()
|
121 |
+
);
|
122 |
+
|
123 |
+
// Call the licensing server.
|
124 |
+
$response = wp_remote_get( add_query_arg( $request, self::STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
|
125 |
+
|
126 |
+
if ( is_wp_error( $response ) )
|
127 |
+
return new WP_Error( 'request-failed', _x( 'Could not contact licensing server', 'licensing', 'WPBDM' ) );
|
128 |
+
|
129 |
+
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
130 |
+
|
131 |
+
if ( ! is_object( $license_data ) || ! $license_data || ! isset( $license_data->license ) || 'valid' !== $license_data->license )
|
132 |
+
return new WP_Error( 'invalid-license', _x( 'License key is invalid', 'licensing', 'WPBDM' ) );
|
133 |
+
|
134 |
+
update_option( 'wpbdp-license-status-' . $module, $license_data->license );
|
135 |
+
|
136 |
+
return array( 'activations_left' => $license_data->activations_left, 'expires' => $license_data->expires );
|
137 |
+
}
|
138 |
+
|
139 |
+
function deactivate_license( $module ) {
|
140 |
+
if ( ! in_array( $module, array_keys( $this->modules ), true ) )
|
141 |
+
return new WP_Error( 'invalid-module', _x( 'Invalid module ID', 'licensing', 'WPBDM' ), $module );
|
142 |
+
|
143 |
+
delete_option( 'wpbdp-license-status-' . $module );
|
144 |
+
|
145 |
+
$key = trim( get_option( 'wpbdp-license-key-' . $module, '' ) );
|
146 |
+
$module_data = $this->modules[ $module ];
|
147 |
+
|
148 |
+
$request = array(
|
149 |
+
'edd_action' => 'deactivate_license',
|
150 |
+
'license' => $key,
|
151 |
+
'item_name' => urlencode( $module_data['name'] ),
|
152 |
+
'url' => home_url()
|
153 |
+
);
|
154 |
+
|
155 |
+
// Call the licensing server.
|
156 |
+
$response = wp_remote_get( add_query_arg( $request, self::STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
|
157 |
+
|
158 |
+
if ( is_wp_error( $response ) )
|
159 |
+
return new WP_Error( 'request-failed', _x( 'Could not contact licensing server', 'licensing', 'WPBDM' ) );
|
160 |
+
|
161 |
+
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
162 |
+
|
163 |
+
delete_option( 'wpbdp-license-status-' . $module );
|
164 |
+
|
165 |
+
if ( ! is_object( $license_data ) || ! $license_data || ! isset( $license_data->license ) )
|
166 |
+
return new WP_Error( 'invalid-license', _x( 'License key is invalid', 'licensing', 'WPBDM' ) );
|
167 |
+
|
168 |
+
if ( 'deactivated' !== $license_data->license )
|
169 |
+
return new WP_Error( 'deactivation-failed', _x( 'Deactivation failed', 'licensing', 'WPBDM' ) );
|
170 |
+
|
171 |
+
return true;
|
172 |
+
}
|
173 |
+
|
174 |
+
function sort_modules_by_name( $x, $y ) {
|
175 |
+
return strncasecmp( $x['name'], $y['name'], 4 );
|
176 |
+
}
|
177 |
+
|
178 |
+
function register_module( $name = '', $module = '', $version = '' ) {
|
179 |
+
$module = trim( $module );
|
180 |
+
$name = trim( $name );
|
181 |
+
$module_name = trim( str_replace( '.php', '', basename( $module ) ) );
|
182 |
+
$version = trim( $version );
|
183 |
+
|
184 |
+
if ( ! $module || !$module_name || ! $version )
|
185 |
+
return false;
|
186 |
+
|
187 |
+
$this->modules[ $module_name ] = array( 'license' => get_option( 'wpbdp-license-key-' . $module_name, '' ),
|
188 |
+
'license_status' => get_option( 'wpbdp-license-status-' . $module_name, 'invalid' ),
|
189 |
+
'id' => $module_name,
|
190 |
+
'file' => $module,
|
191 |
+
'name' => $name ? $name : $module_name,
|
192 |
+
'version' => $version );
|
193 |
+
|
194 |
+
// Keep modules sorted by name.
|
195 |
+
uasort( $this->modules, array( &$this, 'sort_modules_by_name' ) );
|
196 |
+
return in_array( $this->modules[ $module_name ]['license_status'], array( 'valid', 'expired' ), true );
|
197 |
+
}
|
198 |
+
|
199 |
+
public function admin_init() {
|
200 |
+
//delete_transient( 'wpbdp-license-check-data' ); do_action( 'wpbdp_license_check' );
|
201 |
+
foreach ( $this->modules as $module => $data ) {
|
202 |
+
new EDD_SL_Plugin_Updater( self::STORE_URL,
|
203 |
+
$data['file'],
|
204 |
+
array( 'version' => $data['version'],
|
205 |
+
'license' => $data['license'],
|
206 |
+
'item_name' => $data['name'],
|
207 |
+
'author' => 'D. Rodenbaugh' ) );
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
public function admin_notices() {
|
212 |
+
$invalid = array();
|
213 |
+
$expired = array();
|
214 |
+
|
215 |
+
foreach ( $this->modules as $module => $data ) {
|
216 |
+
switch ( $data['license_status'] ) {
|
217 |
+
case 'valid':
|
218 |
+
break;
|
219 |
+
case 'expired':
|
220 |
+
$expired[] = $data;
|
221 |
+
break;
|
222 |
+
default:
|
223 |
+
$invalid[] = $data;
|
224 |
+
break;
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
if ( $invalid ) {
|
229 |
+
echo '<div class="error"><p>';
|
230 |
+
echo '<b>' . _x( 'Business Directory - License Key Required', 'licensing', 'WPBDM' ) . '</b><br />';
|
231 |
+
echo str_replace( '<a>',
|
232 |
+
'<a href="' . esc_url( admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=licenses' ) ) . '">',
|
233 |
+
_x( 'The following premium modules will not work until a valid license key is provided. Go to <a>Manage Options - Licenses</a> to enter your license information.',
|
234 |
+
'licensing',
|
235 |
+
'WPBDM' ) );
|
236 |
+
echo '<br /><br />';
|
237 |
+
|
238 |
+
foreach ( $invalid as $d )
|
239 |
+
echo '• ' . $d['name'] . ' ' . $d['version'] . '<br />';
|
240 |
+
|
241 |
+
echo '</p></div>';
|
242 |
+
}
|
243 |
+
|
244 |
+
// Expired licenses.
|
245 |
+
if ( $expired ) {
|
246 |
+
$check_data = get_transient( 'wpbdp-license-check-data' );
|
247 |
+
|
248 |
+
foreach ( $expired as $d ) {
|
249 |
+
if ( $check_data && is_array( $check_data['warning-dismissed'] ) && in_array( $d['id'], $check_data['warning-dismissed'], true ) )
|
250 |
+
continue;
|
251 |
+
|
252 |
+
echo '<div class="error wpbdp-license-expired-warning">';
|
253 |
+
echo '<p>';
|
254 |
+
echo '<b>'. _x( 'Business Directory - License Key Expired', 'licensing', 'WPBDM' ) . '</b><br />';
|
255 |
+
printf( _x( 'The license key for <span class="module-name">%s %s</span> has expired. The module will continue to work but you will not receive any more updates until the license is renewed.',
|
256 |
+
'licensing',
|
257 |
+
'WPBDM' ), $d['name'], $d['version'] );
|
258 |
+
echo '<br /><br />';
|
259 |
+
echo '<a href="#" class="dismiss button" data-module="' . esc_attr( $d['id'] ) . '" data-nonce="' . wp_create_nonce( 'dismiss warning' ) . '">' . _x( 'Remind me later', 'licensing', 'WPBDM' ) . '</a> ';
|
260 |
+
$url = add_query_arg( array( 'item_name' => urlencode( $d['name'] ), 'edd_license_key' => urlencode( $d['license'] ) ), 'http://businessdirectoryplugin.com/checkout/' );
|
261 |
+
echo '<a href="' . esc_url( $url ) . '" target="_blank" class="button-primary">' . _x( 'Renew License Key', 'licensing', 'WPBDM' ) . '</a>';
|
262 |
+
echo '</p></div>';
|
263 |
+
}
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
function license_check() {
|
268 |
+
if ( ! $this->modules )
|
269 |
+
return;
|
270 |
+
|
271 |
+
wpbdp_log( 'Performing (scheduled) license check.' );
|
272 |
+
$data = get_transient( 'wpbdp-license-check-data' );
|
273 |
+
|
274 |
+
if ( ! $data ) {
|
275 |
+
$data = array( 'date' => current_time('mysql'), 'warning-dismissed' => false );
|
276 |
+
|
277 |
+
foreach ( $this->modules as $module ) {
|
278 |
+
if ( null == ( $status = $this->check_module_license( $module['id'] ) ) )
|
279 |
+
continue;
|
280 |
+
|
281 |
+
if ( ! isset( $data[ $status ] ) )
|
282 |
+
$data[ $status ] = array();
|
283 |
+
|
284 |
+
$data[ $status ][ $module['id'] ] = $module['license'];
|
285 |
+
update_option( 'wpbdp-license-status-' . $module['id'], $status );
|
286 |
+
}
|
287 |
+
|
288 |
+
set_transient( 'wpbdp-license-check-data', $data, 1 * WEEK_IN_SECONDS );
|
289 |
+
}
|
290 |
+
}
|
291 |
+
|
292 |
+
function check_module_license( $module ) {
|
293 |
+
$data = isset( $this->modules[ $module ] ) ? $this->modules[ $module ] : null;
|
294 |
+
|
295 |
+
if ( ! $data || ! isset( $data['license'] ) || ! $data['license'] )
|
296 |
+
return null;
|
297 |
+
|
298 |
+
$request = array( 'edd_action' => 'check_license',
|
299 |
+
'license' => $data['license'],
|
300 |
+
'item_name' => urlencode( $data['name'] ),
|
301 |
+
'url' => home_url() );
|
302 |
+
$response = wp_remote_get( add_query_arg( $request, self::STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
|
303 |
+
|
304 |
+
if ( is_wp_error( $response ) )
|
305 |
+
return null;
|
306 |
+
|
307 |
+
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
308 |
+
|
309 |
+
if ( ! is_object( $license_data ) || ! $license_data || ! isset( $license_data->license ) )
|
310 |
+
return null;
|
311 |
+
|
312 |
+
return $license_data->license;
|
313 |
+
//return ( 'valid' == $license_data->license ? true : false );
|
314 |
+
}
|
315 |
+
|
316 |
+
function ajax_activate_license() {
|
317 |
+
$module = isset( $_POST['module'] ) ? trim( $_POST['module'] ) : '';
|
318 |
+
$nonce = isset( $_POST['nonce'] ) ? trim( $_POST['nonce'] ) : '';
|
319 |
+
$key = isset( $_POST['key'] ) ? trim( $_POST['key'] ) : '';
|
320 |
+
|
321 |
+
if ( ! $module || ! $nonce || ! wp_verify_nonce( $nonce, 'license activation' ) )
|
322 |
+
die();
|
323 |
+
|
324 |
+
update_option( 'wpbdp-license-key-' . $module, $key );
|
325 |
+
$result = $this->activate_license( $module, $key );
|
326 |
+
|
327 |
+
$response = new WPBDP_Ajax_Response();
|
328 |
+
|
329 |
+
if ( is_wp_error( $result ) )
|
330 |
+
$response->send_error( sprintf( _x( 'Could not activate license: %s.', 'licensing', 'WPBDM' ), $result->get_error_message() ) );
|
331 |
+
|
332 |
+
$response->set_message( _x( 'License activated', 'licensing', 'WPBDM' ) );
|
333 |
+
$response->send();
|
334 |
+
}
|
335 |
+
|
336 |
+
function ajax_deactivate_license() {
|
337 |
+
$module = isset( $_POST['module'] ) ? trim( $_POST['module'] ) : '';
|
338 |
+
$nonce = isset( $_POST['nonce'] ) ? trim( $_POST['nonce'] ) : '';
|
339 |
+
|
340 |
+
if ( ! $module || ! $nonce || ! wp_verify_nonce( $nonce, 'license activation' ) )
|
341 |
+
die();
|
342 |
+
|
343 |
+
$result = $this->deactivate_license( $module );
|
344 |
+
|
345 |
+
$response = new WPBDP_Ajax_Response();
|
346 |
+
|
347 |
+
if ( is_wp_error( $result ) )
|
348 |
+
$response->send_error( sprintf( _x( 'Could not deactivate license: %s.', 'licensing', 'WPBDM' ), $result->get_error_message() ) );
|
349 |
+
|
350 |
+
$response->set_message( _x( 'License deactivated', 'licensing', 'WPBDM' ) );
|
351 |
+
$response->send();
|
352 |
+
}
|
353 |
+
|
354 |
+
function ajax_dismiss_license_warning() {
|
355 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
356 |
+
$module = isset( $_POST['module'] ) ? $_POST['module'] : '';
|
357 |
+
|
358 |
+
$res = new WPBDP_Ajax_Response();
|
359 |
+
|
360 |
+
if ( ! wp_verify_nonce( $nonce, 'dismiss warning' ) )
|
361 |
+
$res->send_error();
|
362 |
+
|
363 |
+
$data = get_transient( 'wpbdp-license-check-data' );
|
364 |
+
|
365 |
+
if ( ! is_array( $data['warning-dismissed'] ) )
|
366 |
+
$data['warning-dismissed'] = array();
|
367 |
+
|
368 |
+
if ( ! in_array( $module, $data['warning-dismissed'], true ) )
|
369 |
+
$data['warning-dismissed'][] = $module;
|
370 |
+
|
371 |
+
set_transient( 'wpbdp-license-check-data', $data, 1 * WEEK_IN_SECONDS );
|
372 |
+
|
373 |
+
$res->send();
|
374 |
+
}
|
375 |
+
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* @since 3.4.2
|
380 |
+
*/
|
381 |
+
function wpbdp_licensing_register_module( $name, $file_, $version ) {
|
382 |
+
global $wpbdp;
|
383 |
+
return true;
|
384 |
+
return $wpbdp->licensing->register_module( $name, $file_, $version );
|
385 |
+
}
|
core/listings.php
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-listing.php' );
|
3 |
+
require_once( WPBDP_PATH . 'core/class-listing-upgrade-api.php' );
|
4 |
+
require_once( WPBDP_PATH . 'core/class-listings-api.php' );
|
5 |
+
|
core/payment.php
ADDED
@@ -0,0 +1,668 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-payment.php' );
|
3 |
+
|
4 |
+
/*
|
5 |
+
* Fees/Payment API
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! class_exists( 'WPBDP_PaymentsAPI' ) ) {
|
9 |
+
|
10 |
+
class WPBDP_FeesAPI {
|
11 |
+
|
12 |
+
public function __construct() { }
|
13 |
+
|
14 |
+
public static function get_free_fee() {
|
15 |
+
$fee = new StdClass();
|
16 |
+
$fee->id = 0;
|
17 |
+
$fee->label = _x('Free Listing', 'fees-api', 'WPBDM');
|
18 |
+
$fee->amount = 0.0;
|
19 |
+
$fee->images = intval(wpbdp_get_option('free-images'));
|
20 |
+
$fee->days = intval(wpbdp_get_option('listing-duration'));
|
21 |
+
$fee->categories = array('all' => true, 'categories' => array());
|
22 |
+
$fee->extra_data = null;
|
23 |
+
|
24 |
+
return $fee;
|
25 |
+
}
|
26 |
+
|
27 |
+
private function normalize(&$fee) {
|
28 |
+
$fee->categories = unserialize($fee->categories);
|
29 |
+
$fee->extra_data = unserialize( $fee->extra_data );
|
30 |
+
}
|
31 |
+
|
32 |
+
public function _sort_fees( &$fees ) {
|
33 |
+
$order = wpbdp_get_option( 'fee-order' );
|
34 |
+
$res = array_merge( array(), $fees );
|
35 |
+
|
36 |
+
if ( 'custom' == $order['method'] ) {
|
37 |
+
usort( $res, create_function( '$a, $b', 'return $a->weight < $b->weight;' ) );
|
38 |
+
return $res;
|
39 |
+
}
|
40 |
+
|
41 |
+
$field = $order['method'];
|
42 |
+
$asc = ( 'asc' == $order['order'] ) ? true : false;
|
43 |
+
|
44 |
+
switch ( $field ) {
|
45 |
+
case 'label':
|
46 |
+
usort( $res, create_function( '$a, $b', 'return strnatcmp( $a->label, $b->label );' ) );
|
47 |
+
break;
|
48 |
+
case 'days':
|
49 |
+
usort( $res, create_function( '$a, $b', 'return ( 0 == $a->days ? 1 : ( 0 == $b->days ? -1 : $a->days > $b->days ) );' ) );
|
50 |
+
break;
|
51 |
+
case 'amount':
|
52 |
+
case 'images':
|
53 |
+
usort( $res, create_function( '$a, $b', 'return ($a->' . $field . '*100) > ($b->' . $field . '*100);' ) );
|
54 |
+
break;
|
55 |
+
}
|
56 |
+
|
57 |
+
if ( ! $asc )
|
58 |
+
$res = array_reverse( $res );
|
59 |
+
|
60 |
+
return $res;
|
61 |
+
|
62 |
+
// wpbdp_debug_e( $order, $res );
|
63 |
+
}
|
64 |
+
|
65 |
+
public function get_fees_for_category($catid) {
|
66 |
+
$fees = array();
|
67 |
+
|
68 |
+
if (wpbdp_payments_api()->payments_possible()) {
|
69 |
+
$parent_categories = wpbdp_get_parent_categories($catid);
|
70 |
+
array_walk($parent_categories, create_function('&$x', '$x = intval($x->term_id);'));
|
71 |
+
|
72 |
+
foreach ($this->get_fees() as $fee) {
|
73 |
+
if ($fee->categories['all']) {
|
74 |
+
$fees[] = $fee;
|
75 |
+
} else {
|
76 |
+
foreach ($fee->categories['categories'] as $fee_catid) {
|
77 |
+
if (in_array($fee_catid, $parent_categories)) {
|
78 |
+
$fees[] = $fee;
|
79 |
+
break;
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
if (!$fees)
|
87 |
+
$fees[] = $this->get_free_fee();
|
88 |
+
|
89 |
+
return $fees;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function get_fees($categories=null) {
|
93 |
+
global $wpdb;
|
94 |
+
|
95 |
+
if (isset($categories)) {
|
96 |
+
$fees = array();
|
97 |
+
|
98 |
+
foreach ($categories as $catid) {
|
99 |
+
$category_fees = $this->get_fees_for_category($catid);
|
100 |
+
$fees[$catid] = $this->_sort_fees( $category_fees );
|
101 |
+
}
|
102 |
+
|
103 |
+
return $fees;
|
104 |
+
} else {
|
105 |
+
$fees = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wpbdp_fees");
|
106 |
+
|
107 |
+
foreach ($fees as &$fee)
|
108 |
+
$this->normalize($fee);
|
109 |
+
|
110 |
+
$fees = $this->_sort_fees( $fees );
|
111 |
+
|
112 |
+
return $fees;
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
public function get_fee_by_id($id) {
|
117 |
+
global $wpdb;
|
118 |
+
|
119 |
+
if ($id == 0)
|
120 |
+
return $this->get_free_fee();
|
121 |
+
|
122 |
+
if ($fee = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_fees WHERE id = %d", $id))) {
|
123 |
+
$this->normalize($fee);
|
124 |
+
return $fee;
|
125 |
+
}
|
126 |
+
|
127 |
+
return null;
|
128 |
+
}
|
129 |
+
|
130 |
+
public function is_valid_fee($fee=array(), &$errors=null) {
|
131 |
+
if (!is_array($errors)) $errors = array();
|
132 |
+
|
133 |
+
if (!isset($fee['label']) || trim($fee['label']) == '')
|
134 |
+
$errors[] = _x('Fee label is required.', 'fees-api', 'WPBDM');
|
135 |
+
|
136 |
+
if (!isset($fee['amount']) || trim($fee['amount']) == '' || !is_numeric($fee['amount']) || floatval($fee['amount']) < 0.0)
|
137 |
+
$errors[] = _x('Fee amount must be a non-negative decimal number.', 'fees-api', 'WPBDM');
|
138 |
+
|
139 |
+
if (!isset($fee['categories']))
|
140 |
+
$errors[] = _x('Fee must apply to at least one category.', 'fees-api', 'WPBDM');
|
141 |
+
|
142 |
+
if (isset($fee['categories']) && !isset($fee['categories']['all']) && !isset($fee['categories']['categories']))
|
143 |
+
$errors[] = _x('Fee must apply to at least one category.', 'fees-api', 'WPBDM');
|
144 |
+
|
145 |
+
if (!isset($fee['images']) || !is_int($fee['images']) || intval($fee['images']) < 0)
|
146 |
+
$errors[] = _x('Fee allowed images must be a non-negative integer.', 'fees-api', 'WPBDM');
|
147 |
+
|
148 |
+
if (!isset($fee['days']) || !is_int($fee['days']) || intval($fee['days']) < 0) {
|
149 |
+
$errors[] = _x('Fee listing run must be a non-negative integer.', 'fees-api', 'WPBDM');
|
150 |
+
} else {
|
151 |
+
// limit 'duration' because of TIMESTAMP limited range (issue #157).
|
152 |
+
// FIXME: this is not a long-term fix. we should move to DATETIME to avoid this entirely.
|
153 |
+
if ($fee['days'] > 3650) {
|
154 |
+
$errors[] = _x('Fee listing duration must be a number less than 10 years (3650 days).', 'fees-api', 'WPBDM');
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
if ($errors)
|
159 |
+
return false;
|
160 |
+
|
161 |
+
return true;
|
162 |
+
}
|
163 |
+
|
164 |
+
public function add_or_update_fee($fee_=array(), &$errors = null) {
|
165 |
+
global $wpdb;
|
166 |
+
|
167 |
+
$errors = array();
|
168 |
+
|
169 |
+
$fee = $fee_;
|
170 |
+
|
171 |
+
$fee['images'] = intval($fee['images']);
|
172 |
+
$fee['days'] = intval($fee['days']);
|
173 |
+
$fee['categories'] = array();
|
174 |
+
$fee['categories']['all'] = intval(wpbdp_getv($fee_['categories'], 'all', false));
|
175 |
+
$fee['categories']['categories'] = array_map('intval', wpbdp_getv($fee_['categories'], 'categories', array()));
|
176 |
+
|
177 |
+
if (in_array(0, $fee['categories']['categories']))
|
178 |
+
$fee['categories']['all'] = true;
|
179 |
+
|
180 |
+
if ($fee['categories']['all'])
|
181 |
+
$fee['categories']['categories'] = array();
|
182 |
+
|
183 |
+
if (!$fee['categories']['categories'])
|
184 |
+
$fee['categories']['all'] = true;
|
185 |
+
|
186 |
+
// TODO: delete unnecessary categories: if a parent of a category is in the list, remove the category
|
187 |
+
|
188 |
+
if ($this->is_valid_fee($fee, $errors)) {
|
189 |
+
$fee['categories'] = serialize($fee['categories']);
|
190 |
+
|
191 |
+
if ( isset( $fee['id'] ) && !isset( $fee['extra_data'] ) )
|
192 |
+
$fee['extra_data'] = unserialize( $wpdb->get_var( $wpdb->prepare( "SELECT extra_data FROM {$wpdb->prefix}wpbdp_fees WHERE id = %d", $fee['id'] ) ) );
|
193 |
+
|
194 |
+
if ( !isset( $fee['extra_data'] ) || !is_array( $fee['extra_data'] ) )
|
195 |
+
$fee['extra_data'] = array();
|
196 |
+
|
197 |
+
do_action_ref_array( 'wpbdp_fee_before_save', array( &$fee ) );
|
198 |
+
$fee['extra_data'] = $fee['extra_data'] ? serialize( $fee['extra_data'] ) : null;
|
199 |
+
|
200 |
+
if (isset($fee['id'])) {
|
201 |
+
return $wpdb->update("{$wpdb->prefix}wpbdp_fees", $fee, array('id' => $fee['id'])) !== false;
|
202 |
+
} else {
|
203 |
+
return $wpdb->insert("{$wpdb->prefix}wpbdp_fees", $fee);
|
204 |
+
}
|
205 |
+
}
|
206 |
+
|
207 |
+
return false;
|
208 |
+
}
|
209 |
+
|
210 |
+
public function delete_fee($id) {
|
211 |
+
if (is_object($id)) return $this->delete_fee((array) $id);
|
212 |
+
if (is_array($id)) return $this->delete_fee($id['id']);
|
213 |
+
|
214 |
+
global $wpdb;
|
215 |
+
|
216 |
+
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}wpbdp_fees WHERE id = %d", $id));
|
217 |
+
|
218 |
+
return true;
|
219 |
+
}
|
220 |
+
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Finds a fee by its ID. The special ID of 0 is reserved for the "free fee".
|
225 |
+
* @param int $fee_id fee ID
|
226 |
+
* @return object a fee object or NULL if nothing is found
|
227 |
+
* @since 3.0.3
|
228 |
+
*/
|
229 |
+
function wpbdp_get_fee( $fee_id ) {
|
230 |
+
return wpbdp_fees_api()->get_fee_by_id( $fee_id );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Finds fees available for one or more directory categories.
|
235 |
+
* @param int|array $categories term ID or array of term IDs
|
236 |
+
* @return object|
|
237 |
+
* @since 3.0.3
|
238 |
+
*/
|
239 |
+
function wpbdp_get_fees_for_category( $categories=null ) {
|
240 |
+
$categories_ = is_array( $categories ) ? $categories : array( $categories );
|
241 |
+
$results = wpbdp_fees_api()->get_fees( $categories_ );
|
242 |
+
|
243 |
+
return is_array( $categories) ? $results : array_pop( $results );
|
244 |
+
}
|
245 |
+
|
246 |
+
|
247 |
+
|
248 |
+
class WPBDP_PaymentsAPI {
|
249 |
+
|
250 |
+
public function __construct() {
|
251 |
+
$this->gateways = array();
|
252 |
+
|
253 |
+
do_action_ref_array( 'wpbdp_register_gateways', array( &$this ) );
|
254 |
+
add_action( 'wpbdp_register_settings', array( &$this, 'register_gateway_settings' ) );
|
255 |
+
|
256 |
+
add_action( 'WPBDP_Payment::set_payment_method', array( &$this, 'gateway_payment_setup' ), 10, 2 );
|
257 |
+
//add_action( 'WPBDP_Payment::status_change', array( &$this, 'payment_notification' ) );
|
258 |
+
// add_action( 'WPBDP_Payment::before_save', array( &$this, 'gateway_payment_save' ) );
|
259 |
+
}
|
260 |
+
|
261 |
+
public function register_gateway($id, $classorinstance ) {
|
262 |
+
if ( isset( $this->gateways[ $id ] ) )
|
263 |
+
return false;
|
264 |
+
|
265 |
+
if ( ! is_string( $classorinstance ) && ! is_object( $classorinstance ) )
|
266 |
+
return false;
|
267 |
+
|
268 |
+
if ( is_string( $classorinstance ) && ! class_exists( $classorinstance ) )
|
269 |
+
return false;
|
270 |
+
|
271 |
+
$this->gateways[ $id ] = is_object( $classorinstance ) ? $classorinstance : new $classorinstance;
|
272 |
+
return true;
|
273 |
+
}
|
274 |
+
|
275 |
+
public function register_gateway_settings( &$settings ) {
|
276 |
+
foreach ( $this->gateways as &$gateway )
|
277 |
+
$gateway->register_config( $settings );
|
278 |
+
}
|
279 |
+
|
280 |
+
public function get_available_methods( $capabilities = array() ) {
|
281 |
+
$ok_gateways = array();
|
282 |
+
|
283 |
+
if ( ! wpbdp_get_option( 'payments-on' ) )
|
284 |
+
return array();
|
285 |
+
|
286 |
+
foreach ( $this->gateways as $gateway_id => &$gateway ) {
|
287 |
+
if ( wpbdp_get_option( $gateway_id ) || 'dummy' == $gateway_id ) {
|
288 |
+
if ( 0 === count( $gateway->validate_config() ) ) {
|
289 |
+
if ( $capabilities ) {
|
290 |
+
$has_caps = true;
|
291 |
+
|
292 |
+
foreach ( $capabilities as $cap ) {
|
293 |
+
if ( ! in_array( $cap, $gateway->get_capabilities(), true ) ) {
|
294 |
+
$has_caps = false;
|
295 |
+
break;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
if ( $has_caps )
|
300 |
+
$ok_gateways[] = $gateway_id;
|
301 |
+
} else {
|
302 |
+
$ok_gateways[] = $gateway_id;
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
return $ok_gateways;
|
309 |
+
}
|
310 |
+
|
311 |
+
public function payments_possible() {
|
312 |
+
return count( $this->get_available_methods() ) > 0;
|
313 |
+
}
|
314 |
+
|
315 |
+
public function check_config() {
|
316 |
+
if ( wpbdp_get_option( 'featured-on' ) && ! wpbdp_get_option( 'payments-on' ) )
|
317 |
+
return array(
|
318 |
+
sprintf( _x( 'You are offering featured listings but have payments turned off. Go to <a href="%s">Manage Options - Payment</a> to change the payment settings. Until you change this, the <i>Upgrade to Featured</i> option will be disabled.', 'payments-api', 'WPBDM' ), admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=payment' ) )
|
319 |
+
);
|
320 |
+
|
321 |
+
if ( ! wpbdp_get_option( 'payments-on' ) )
|
322 |
+
return array();
|
323 |
+
|
324 |
+
// Check every registered & enabled gateway to see if it is properly configured.
|
325 |
+
$errors = array();
|
326 |
+
$gateway_ok = false;
|
327 |
+
|
328 |
+
foreach ( $this->gateways as $gateway_id => &$gateway ) {
|
329 |
+
if ( ! wpbdp_get_option( $gateway_id ) )
|
330 |
+
continue;
|
331 |
+
|
332 |
+
$gateway_errors = $gateway->validate_config();
|
333 |
+
|
334 |
+
if ( $gateway_errors ) {
|
335 |
+
$gateway_messages = rtrim('• ' . implode(' • ', $gateway_errors), '.');
|
336 |
+
$errors[] = sprintf(_x('The <b>%s</b> gateway is active but not properly configured. The gateway won\'t be available until the following problems are fixed: <b>%s</b>. <br/> Check the <a href="%s">payment settings</a>.', 'payments-api', 'WPBDM'),
|
337 |
+
$gateway->get_name(),
|
338 |
+
$gateway_messages,
|
339 |
+
admin_url('admin.php?page=wpbdp_admin_settings&groupid=payment') );
|
340 |
+
} else {
|
341 |
+
$gateway_ok = true;
|
342 |
+
}
|
343 |
+
}
|
344 |
+
|
345 |
+
if ( ! $gateway_ok ) {
|
346 |
+
$errors[] = sprintf(_x('You have payments turned on but no gateway is active and properly configured. Go to <a href="%s">Manage Options - Payment</a> to change the payment settings. Until you change this, the directory will operate in <i>Free Mode</i>.', 'admin', 'WPBDM'),
|
347 |
+
admin_url('admin.php?page=wpbdp_admin_settings&groupid=payment'));
|
348 |
+
} else {
|
349 |
+
if ( count( $this->get_available_methods() ) >= 2 && $this->is_available( 'payfast' ) ) {
|
350 |
+
$errors[] = __( 'BD detected PayFast and another gateway were enabled. This setup is not recommended due to PayFast supporting only ZAR and the other gateways not supporting this currency.', 'admin', 'WPBDM' );
|
351 |
+
}
|
352 |
+
|
353 |
+
if ( wpbdp_get_option( 'listing-renewal-auto' ) && ! $this->check_capability( 'recurring' ) ) {
|
354 |
+
$errors[] = __( 'You have recurring renewal of listing fees enabled but the payment gateways installed don\'t support recurring payments. Until a gateway that supports recurring payments (such as PayPal) is enabled automatic renewals will be disabled.', 'WPBDM' );
|
355 |
+
}
|
356 |
+
|
357 |
+
if ( wpbdp_get_option( 'listing-renewal-auto' ) && $this->is_available( 'googlewallet' )
|
358 |
+
&& wpbdp_get_option('googlewallet' ) && isset( $_GET['page'] ) && 'wpbdp_admin_fees' == $_GET['page'] ) {
|
359 |
+
$errors[] = __( 'Due to Google Wallet limitations only monthly (30 days) recurring fees are supported by the gateway. All other fees will be charged as non-recurring.', 'WPBDM' );
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
return $errors;
|
364 |
+
}
|
365 |
+
|
366 |
+
public function get_registered_methods() {
|
367 |
+
return $this->gateways;
|
368 |
+
}
|
369 |
+
|
370 |
+
/**
|
371 |
+
* @since 3.5.3
|
372 |
+
*/
|
373 |
+
public function is_available($gateway) {
|
374 |
+
return in_array( $gateway, $this->get_available_methods(), true );
|
375 |
+
}
|
376 |
+
|
377 |
+
public function has_gateway($gateway) {
|
378 |
+
return array_key_exists($gateway, $this->gateways);
|
379 |
+
}
|
380 |
+
|
381 |
+
public function check_capability( $cap ) {
|
382 |
+
foreach ( $this->get_available_methods() as $gateway_id ) {
|
383 |
+
if ( in_array( $cap, $this->gateways[ $gateway_id ]->get_capabilities(), true ) )
|
384 |
+
return true;
|
385 |
+
}
|
386 |
+
|
387 |
+
return false;
|
388 |
+
}
|
389 |
+
|
390 |
+
public function render_payment_page($options_) {
|
391 |
+
$options = array_merge(array(
|
392 |
+
'title' => _x('Checkout', 'payments-api', 'WPBDM'),
|
393 |
+
'item_text' => _x('Pay %1$s through %2$s', 'payments-api', 'WPBDM'),
|
394 |
+
'return_link' => null
|
395 |
+
), $options_);
|
396 |
+
|
397 |
+
$transaction = $this->get_transaction($options['transaction_id']);
|
398 |
+
|
399 |
+
if ( $transaction->status == 'approved' || $transaction->amount == 0.0 ) {
|
400 |
+
return wpbdp_render_msg( _x('Your transaction has been approved.', 'payments-api', 'WPBDM' ) );
|
401 |
+
}
|
402 |
+
|
403 |
+
return wpbdp_render('payment-page', array(
|
404 |
+
'title' => $options['title'],
|
405 |
+
'item_text' => $options['item_text'],
|
406 |
+
'transaction' => $transaction,
|
407 |
+
'payment_methods' => $this->get_available_methods(),
|
408 |
+
'return_link' => $options['return_link']
|
409 |
+
));
|
410 |
+
}
|
411 |
+
|
412 |
+
public function get_transaction_from_uri_id() {
|
413 |
+
if (!isset($_GET['tid']))
|
414 |
+
return null;
|
415 |
+
|
416 |
+
$uri_id_plain = explode('.', urldecode(base64_decode($_GET['tid'])));
|
417 |
+
$transaction_id = $uri_id_plain[0];
|
418 |
+
$transaction_date = $uri_id_plain[1];
|
419 |
+
|
420 |
+
// check transaction date is valid
|
421 |
+
if ($transaction = $this->get_transaction($transaction_id)) {
|
422 |
+
if (strtotime($transaction->created_on) == $transaction_date)
|
423 |
+
return $transaction;
|
424 |
+
}
|
425 |
+
|
426 |
+
return null;
|
427 |
+
}
|
428 |
+
|
429 |
+
/**
|
430 |
+
* @deprecated since 3.4
|
431 |
+
*/
|
432 |
+
public function get_processing_url($gateway, $transaction=null) {
|
433 |
+
throw new Exception( sprintf( 'get_processing_url() is deprecated. Please upgrade your "%s" gateway.', $gateway ) );
|
434 |
+
}
|
435 |
+
|
436 |
+
public function in_test_mode() {
|
437 |
+
return wpbdp_get_option('payments-test-mode');
|
438 |
+
}
|
439 |
+
|
440 |
+
public function get_transaction($transaction_id) {
|
441 |
+
global $wpdb;
|
442 |
+
|
443 |
+
if ($trans = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE id = %d", $transaction_id))) {
|
444 |
+
if ($trans->payerinfo) {
|
445 |
+
$trans->payerinfo = unserialize($trans->payerinfo);
|
446 |
+
} else {
|
447 |
+
$trans->payerinfo = array('name' => '',
|
448 |
+
'email' => '');
|
449 |
+
}
|
450 |
+
|
451 |
+
if ($trans->extra_data) {
|
452 |
+
$trans->extra_data = unserialize($trans->extra_data);
|
453 |
+
} else {
|
454 |
+
$trans->extra_data = array();
|
455 |
+
}
|
456 |
+
|
457 |
+
return $trans;
|
458 |
+
}
|
459 |
+
|
460 |
+
return null;
|
461 |
+
}
|
462 |
+
|
463 |
+
public function get_transactions($listing_id) {
|
464 |
+
global $wpdb;
|
465 |
+
|
466 |
+
$transactions = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE listing_id = %d", $listing_id));
|
467 |
+
|
468 |
+
foreach ($transactions as &$trans) {
|
469 |
+
$trans->payerinfo = unserialize($trans->payerinfo);
|
470 |
+
$trans->extra_data = unserialize($trans->extra_data);
|
471 |
+
|
472 |
+
if (!$trans->payerinfo)
|
473 |
+
$trans->payerinfo = array('name' => '', 'email' => '');
|
474 |
+
}
|
475 |
+
|
476 |
+
return $transactions;
|
477 |
+
}
|
478 |
+
|
479 |
+
public function get_last_transaction($listing_id) {
|
480 |
+
global $wpdb;
|
481 |
+
|
482 |
+
$transaction = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_payments WHERE listing_id = %d ORDER BY id DESC LIMIT 1", $listing_id));
|
483 |
+
|
484 |
+
if ($transaction) {
|
485 |
+
$transaction->payerinfo = unserialize($transaction->payerinfo);
|
486 |
+
$transaction->extra_data = unserialize($transaction->extra_data);
|
487 |
+
|
488 |
+
if (!$transaction->payerinfo)
|
489 |
+
$transaction->payerinfo = array('name' => '', 'email' => '');
|
490 |
+
|
491 |
+
return $transaction;
|
492 |
+
}
|
493 |
+
|
494 |
+
return null;
|
495 |
+
}
|
496 |
+
|
497 |
+
/**
|
498 |
+
* Resolves ?wpbdpx=payments requests.
|
499 |
+
* @since 3.3
|
500 |
+
*/
|
501 |
+
public function process_request() {
|
502 |
+
$action = isset( $_GET['action'] ) ? trim( $_GET['action'] ) : '';
|
503 |
+
$payment = isset( $_GET['payment_id'] ) ? WPBDP_Payment::get( intval( $_GET['payment_id'] ) ) : null;
|
504 |
+
$gid = isset( $_GET['gid'] ) ? trim( $_GET['gid'] ) : '';
|
505 |
+
|
506 |
+
if ( ! in_array( $action, array( 'postback', 'process', 'notify', 'return', 'cancel' ) ) || ( ! $payment && ! $gid ) )
|
507 |
+
return;
|
508 |
+
|
509 |
+
unset( $_GET['action'] );
|
510 |
+
|
511 |
+
if ( $payment )
|
512 |
+
unset( $_GET['payment_id'] );
|
513 |
+
|
514 |
+
if ( $gid )
|
515 |
+
unset( $_GET['gid'] );
|
516 |
+
|
517 |
+
$gateway_id = $payment ? $payment->get_gateway() : $gid;
|
518 |
+
|
519 |
+
if ( ! $gateway_id || ! isset( $this->gateways[ $gateway_id ] ) )
|
520 |
+
return;
|
521 |
+
|
522 |
+
if ( ! $payment )
|
523 |
+
$this->gateways[ $gateway_id ]->process_generic( $action );
|
524 |
+
else
|
525 |
+
$this->gateways[ $gateway_id ]->process( $payment, $action );
|
526 |
+
}
|
527 |
+
|
528 |
+
public function render_unsubscribe_integration( &$category, &$listing ) {
|
529 |
+
global $wpdb;
|
530 |
+
|
531 |
+
if ( ! $category || ! $listing )
|
532 |
+
return;
|
533 |
+
|
534 |
+
$payment = WPBDP_Payment::get( $category->payment_id );
|
535 |
+
|
536 |
+
if ( ! $payment )
|
537 |
+
return '';
|
538 |
+
|
539 |
+
$gateway = $payment->get_gateway();
|
540 |
+
|
541 |
+
if ( ! isset( $this->gateways[ $gateway ] ) )
|
542 |
+
return '';
|
543 |
+
|
544 |
+
return $this->gateways[ $gateway ]->render_unsubscribe_integration( $category, $listing );
|
545 |
+
}
|
546 |
+
|
547 |
+
/**
|
548 |
+
* Renders an invoice table for a given payment.
|
549 |
+
* @param $payment WPBDP_Payment
|
550 |
+
* @return string HTML output.
|
551 |
+
* @since 3.4
|
552 |
+
*/
|
553 |
+
public function render_invoice( &$payment ) {
|
554 |
+
return wpbdp_render( 'payment/payment_items', array( 'payment' => $payment ), false );
|
555 |
+
}
|
556 |
+
|
557 |
+
public function render_details( &$payment ) {
|
558 |
+
$html = '';
|
559 |
+
$html .= '<div class="wpbdp-payment-details">';
|
560 |
+
$html .= '<h4>' . _x( 'Payment Details', 'payments', 'WPBDM' ) . '</h4>';
|
561 |
+
|
562 |
+
// TODO: better payment information.
|
563 |
+
// if ( ! $payment->is_pending() ) {
|
564 |
+
// $html .= '<dl class="details">';
|
565 |
+
// $html .= '<dt>' . _x( 'Gateway', 'payments', 'WPBDM' ) . '</dt>';
|
566 |
+
// $html .= '<dd>' . $payment->get_gateway() && isset( $this->gateways[ $payment->get_gateway() ] ) ? $this->gateways[ $payment->get_gateway() ]->get_name() : '–' . '</dd>';
|
567 |
+
// $html .= '</dl>';
|
568 |
+
// }
|
569 |
+
|
570 |
+
$html .= $this->render_invoice( $payment );
|
571 |
+
$html .= '</div>';
|
572 |
+
|
573 |
+
return $html;
|
574 |
+
}
|
575 |
+
|
576 |
+
/**
|
577 |
+
* Renders payment method selection for a given payment. Takes into account gateways supporting recurring items.
|
578 |
+
* @param $payment WPBDP_Payment
|
579 |
+
* @return string HTML output.
|
580 |
+
* @since 3.4
|
581 |
+
*/
|
582 |
+
public function render_payment_method_selection( &$payment ) {
|
583 |
+
$payment_methods = $this->get_available_methods( $payment->has_item_type( 'recurring_fee' ) ? array( 'recurring' ) : array() );
|
584 |
+
|
585 |
+
$html = '';
|
586 |
+
$html .= '<div class="wpbdp-payment-method-selection">';
|
587 |
+
$html .= '<h4>' . _x( 'Payment Method', 'checkout', 'WPBDM' ) . '</h4>';
|
588 |
+
|
589 |
+
$html .= '<select name="payment_method">';
|
590 |
+
$html .= '<option value="">-- Select a payment method --</option>';
|
591 |
+
foreach ( $payment_methods as $method_id ) {
|
592 |
+
$html .= '<option value="' . $method_id . '">' . $this->gateways[ $method_id ]->get_name() . '</option>';
|
593 |
+
}
|
594 |
+
$html .= '</select>';
|
595 |
+
$html .= '</div>';
|
596 |
+
|
597 |
+
return $html;
|
598 |
+
}
|
599 |
+
|
600 |
+
// TODO: dodoc
|
601 |
+
public function render_payment_method_integration( &$payment ) {
|
602 |
+
$gateway_id = $payment->get_gateway();
|
603 |
+
|
604 |
+
if ( ! isset( $this->gateways[ $gateway_id ] ) )
|
605 |
+
throw new Exception('Unknown gateway for payment.'); // TODO: maybe allow re-selection of the gateway?
|
606 |
+
|
607 |
+
return $this->gateways[ $gateway_id ]->render_integration( $payment );
|
608 |
+
}
|
609 |
+
|
610 |
+
// TODO: dodoc
|
611 |
+
public function render_standard_checkout_page( &$payment, $opts = array() ) {
|
612 |
+
if ( $payment->is_completed() )
|
613 |
+
return;
|
614 |
+
|
615 |
+
$opts = wp_parse_args( $opts,
|
616 |
+
array( 'return_link' => '<a href="' . wpbdp_get_page_link( 'main' ) . '">' . _x( 'Return to Directory.', 'payment', 'WPBDM' ) . '</a>' )
|
617 |
+
);
|
618 |
+
|
619 |
+
$html = '';
|
620 |
+
|
621 |
+
if ( $payment->is_pending() && $payment->has_been_processed() ) {
|
622 |
+
$html .= '<p>' . _x( 'Your payment is being processed by the payment gateway. Please reload this page in a moment to see if the status has changed or contact the site administrator.', 'payments', 'WPBDM' ) . '</p>';
|
623 |
+
} elseif ( $payment->is_rejected() ) {
|
624 |
+
if ( $opts['retry_rejected'] ) {
|
625 |
+
$html .= '<p>' . _x( 'The payment has been rejected by the payment gateway. Please contact the site administrator if you think there is an error or click "Change Payment Method" to select another payment method and try again.', 'payments', 'WPBDM' ) . '</p>';
|
626 |
+
$html .= '<p><a href="' . add_query_arg( 'change_payment_method', 1 ) . '">' . _x( 'Change Payment Method', 'payments', 'WPBDM' ) . '</a></p>';
|
627 |
+
} else {
|
628 |
+
$html .= '<p>' . _x( 'The payment has been rejected by the payment gateway. Please contact the site administrator if you think there is an error.', 'payments', 'WPBDM' ) . '</p>';
|
629 |
+
}
|
630 |
+
} elseif ( $payment->is_canceled() ) {
|
631 |
+
$html .= '<p>' . _x( 'The payment has been canceled at your request.', 'payments', 'WPBDM' ) . '</p>';
|
632 |
+
} elseif ( $payment->is_pending() && $payment->get_gateway() ) {
|
633 |
+
$html .= $this->render_invoice( $payment );
|
634 |
+
$html .= $this->render_payment_method_integration( $payment );
|
635 |
+
}
|
636 |
+
|
637 |
+
if ( ! $opts['retry_rejected'] && $opts['return_link'] )
|
638 |
+
$html .= '<p>' . $opts['return_link'] . '</p>';
|
639 |
+
|
640 |
+
return $html;
|
641 |
+
}
|
642 |
+
|
643 |
+
/**
|
644 |
+
* @since 3.4.2
|
645 |
+
*/
|
646 |
+
public function gateway_payment_setup( &$payment, $method_id = '' ) {
|
647 |
+
if ( ! $method_id || ! isset( $this->gateways[ $method_id ] ) )
|
648 |
+
return;
|
649 |
+
|
650 |
+
$gateway = $this->gateways[ $method_id ];
|
651 |
+
$gateway->setup_payment( $payment );
|
652 |
+
}
|
653 |
+
|
654 |
+
// public function payment_notification( &$payment ) {
|
655 |
+
// if ( ! in_array( 'payment-status-change', wpbdp_get_option( 'user-notifications' ), true ) )
|
656 |
+
// return;
|
657 |
+
//
|
658 |
+
// if ( 0.0 == $payment->get_total() )
|
659 |
+
// return;
|
660 |
+
//
|
661 |
+
//
|
662 |
+
//
|
663 |
+
// wpbdp_debug_e( $payment );
|
664 |
+
// }
|
665 |
+
|
666 |
+
}
|
667 |
+
|
668 |
+
}
|
core/seo.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class WPBDP_SEO {
|
4 |
+
|
5 |
+
public static function is_wp_seo_enabled() {
|
6 |
+
return defined( 'WPSEO_VERSION' ) ? true : false;
|
7 |
+
}
|
8 |
+
|
9 |
+
public static function listing_title( $listing_id ) {
|
10 |
+
if ( self::is_wp_seo_enabled() ) {
|
11 |
+
global $wpseo_front;
|
12 |
+
|
13 |
+
$title = $wpseo_front->get_content_title( get_post( $listing_id ) );
|
14 |
+
$title = esc_html( strip_tags( stripslashes( apply_filters( 'wpseo_title', $title ) ) ) );
|
15 |
+
|
16 |
+
return $title;
|
17 |
+
}
|
18 |
+
|
19 |
+
return get_the_title( $listing_id );
|
20 |
+
}
|
21 |
+
|
22 |
+
public static function listing_og_description( $listing_id ) {
|
23 |
+
if ( self::is_wp_seo_enabled() ) {
|
24 |
+
global $wpseo_front;
|
25 |
+
global $post;
|
26 |
+
|
27 |
+
$prev_post = $post;
|
28 |
+
$post = get_post( $listing_id );
|
29 |
+
$desc = $wpseo_front->metadesc( false );
|
30 |
+
$post = $prev_post;
|
31 |
+
|
32 |
+
return $desc;
|
33 |
+
}
|
34 |
+
|
35 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
36 |
+
return $listing->get_field_value( 'excerpt' );
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
core/templates-generic.php
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function wpbdp_render_page($template, $vars=array(), $echo_output=false) {
|
4 |
+
if ($vars) {
|
5 |
+
extract($vars);
|
6 |
+
}
|
7 |
+
|
8 |
+
ob_start();
|
9 |
+
include($template);
|
10 |
+
$html = ob_get_contents();
|
11 |
+
ob_end_clean();
|
12 |
+
|
13 |
+
if ($echo_output)
|
14 |
+
echo $html;
|
15 |
+
|
16 |
+
return $html;
|
17 |
+
}
|
18 |
+
|
19 |
+
function wpbdp_locate_template($template, $allow_override=true, $try_defaults=true) {
|
20 |
+
$template_file = '';
|
21 |
+
|
22 |
+
if (!is_array($template))
|
23 |
+
$template = array($template);
|
24 |
+
|
25 |
+
if ($allow_override) {
|
26 |
+
$search_for = array();
|
27 |
+
|
28 |
+
foreach ($template as $t) {
|
29 |
+
$search_for[] = $t . '.tpl.php';
|
30 |
+
$search_for[] = $t . '.php';
|
31 |
+
$search_for[] = 'single/' . $t . '.tpl.php';
|
32 |
+
$search_for[] = 'single/' . $t . '.php';
|
33 |
+
}
|
34 |
+
|
35 |
+
$template_file = locate_template($search_for);
|
36 |
+
}
|
37 |
+
|
38 |
+
if (!$template_file && $try_defaults) {
|
39 |
+
foreach ($template as $t) {
|
40 |
+
$template_path = WPBDP_TEMPLATES_PATH . '/' . $t . '.tpl.php';
|
41 |
+
|
42 |
+
if (file_exists($template_path)) {
|
43 |
+
$template_file = $template_path;
|
44 |
+
break;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
return $template_file;
|
50 |
+
}
|
51 |
+
|
52 |
+
function wpbdp_render($template, $vars=array(), $allow_override=true) {
|
53 |
+
$vars = wp_parse_args($vars, array(
|
54 |
+
'__page__' => array(
|
55 |
+
'class' => array(),
|
56 |
+
'content_class' => array(),
|
57 |
+
'before_content' => '')));
|
58 |
+
$template_name = is_array( $template ) ? $template[0] : $template;
|
59 |
+
$vars = apply_filters('wpbdp_template_vars', $vars, $template_name);
|
60 |
+
return apply_filters( "wpbdp_render_{$template_name}", wpbdp_render_page(wpbdp_locate_template($template, $allow_override), $vars, false) );
|
61 |
+
}
|
62 |
+
|
63 |
+
function wpbdp_render_msg($msg, $type='status') {
|
64 |
+
$html = '';
|
65 |
+
$html .= sprintf('<div class="wpbdp-msg %s">%s</div>', $type, $msg);
|
66 |
+
return $html;
|
67 |
+
}
|
68 |
+
|
69 |
+
function _wpbdp_template_mode($template) {
|
70 |
+
if ( wpbdp_locate_template(array('businessdirectory-' . $template, 'wpbusdirman-' . $template), true, false) )
|
71 |
+
return 'template';
|
72 |
+
return 'page';
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Displays a reCAPTCHA field using the configured settings.
|
77 |
+
* @return string HTML for the reCAPTCHA field.
|
78 |
+
* @since 3.4.2
|
79 |
+
*/
|
80 |
+
function wpbdp_recaptcha() {
|
81 |
+
$public_key = wpbdp_get_option( 'recaptcha-public-key' );
|
82 |
+
|
83 |
+
if ( ! $public_key )
|
84 |
+
return '';
|
85 |
+
|
86 |
+
if ( ! function_exists( 'recaptcha_get_html' ) )
|
87 |
+
require_once( WPBDP_PATH . 'vendors/recaptcha/recaptchalib.php' );
|
88 |
+
|
89 |
+
return recaptcha_get_html( $public_key );
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Validates reCAPTCHA input.
|
94 |
+
* @return boolean TRUE if validation succeeded, FALSE otherwise.
|
95 |
+
* @since 3.4.2
|
96 |
+
*/
|
97 |
+
function wpbdp_recaptcha_check_answer( &$error_msg = null ) {
|
98 |
+
$private_key = wpbdp_get_option( 'recaptcha-private-key' );
|
99 |
+
|
100 |
+
if ( ! $private_key )
|
101 |
+
return true;
|
102 |
+
|
103 |
+
if ( ! function_exists( 'recaptcha_check_answer' ) )
|
104 |
+
require_once( WPBDP_PATH . 'vendors/recaptcha/recaptchalib.php' );
|
105 |
+
|
106 |
+
$resp = recaptcha_check_answer( $private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
|
107 |
+
|
108 |
+
if ( ! $resp->is_valid )
|
109 |
+
$error_msg = $resp->error;
|
110 |
+
|
111 |
+
return $resp->is_valid;
|
112 |
+
}
|
core/templates-listings.php
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Displays a single listing view taking into account all of the theme overrides.
|
5 |
+
* @param mixed $listing_id listing object or listing id to display.
|
6 |
+
* @param string $view 'single' for single view or 'excerpt' for summary view.
|
7 |
+
* @return string HTML output.
|
8 |
+
*/
|
9 |
+
function wpbdp_render_listing($listing_id=null, $view='single', $echo=false) {
|
10 |
+
if (is_object($listing_id)) $listing_id = $listing_id->ID;
|
11 |
+
|
12 |
+
global $post;
|
13 |
+
$listings_api = wpbdp_listings_api();
|
14 |
+
|
15 |
+
if ($listing_id) {
|
16 |
+
$args = array( 'post_type' => WPBDP_POST_TYPE, 'p' => $listing_id );
|
17 |
+
|
18 |
+
if ( ! current_user_can( 'edit_posts') )
|
19 |
+
$args['post_status'] = 'publish';
|
20 |
+
|
21 |
+
query_posts( $args );
|
22 |
+
|
23 |
+
if (have_posts()) the_post();
|
24 |
+
}
|
25 |
+
|
26 |
+
if (!$post || $post->post_type != WPBDP_POST_TYPE) {
|
27 |
+
return '';
|
28 |
+
}
|
29 |
+
|
30 |
+
if ($view == 'excerpt')
|
31 |
+
$html = _wpbdp_render_excerpt();
|
32 |
+
else
|
33 |
+
$html = _wpbdp_render_single();
|
34 |
+
|
35 |
+
if ($listing_id)
|
36 |
+
wp_reset_query();
|
37 |
+
|
38 |
+
if ($echo)
|
39 |
+
echo $html;
|
40 |
+
|
41 |
+
return $html;
|
42 |
+
}
|
43 |
+
|
44 |
+
function _wpbdp_render_single() {
|
45 |
+
global $post;
|
46 |
+
|
47 |
+
$html = '';
|
48 |
+
|
49 |
+
$sticky_status = wpbdp_listings_api()->get_sticky_status($post->ID);
|
50 |
+
|
51 |
+
$html .= sprintf( '<div id="wpbdp-listing-%d" class="wpbdp-listing wpbdp-listing-single %s %s %s" itemscope itemtype="http://schema.org/LocalBusiness">',
|
52 |
+
$post->ID,
|
53 |
+
'single',
|
54 |
+
$sticky_status,
|
55 |
+
apply_filters( 'wpbdp_listing_view_css', '', $post->ID ) );
|
56 |
+
$html .= apply_filters('wpbdp_listing_view_before', '', $post->ID, 'single');
|
57 |
+
$html .= wpbdp_capture_action('wpbdp_before_single_view', $post->ID);
|
58 |
+
|
59 |
+
$sticky_tag = '';
|
60 |
+
if ($sticky_status == 'sticky')
|
61 |
+
$sticky_tag = sprintf('<div class="stickytag"><img src="%s" alt="%s" border="0" title="%s"></div>',
|
62 |
+
WPBDP_URL . 'core/images/featuredlisting.png',
|
63 |
+
_x('Featured Listing', 'templates', 'WPBDM'),
|
64 |
+
the_title(null, null, false));
|
65 |
+
|
66 |
+
$d = WPBDP_ListingFieldDisplayItem::prepare_set( $post->ID, 'listing' );
|
67 |
+
$listing_fields = implode( '', WPBDP_ListingFieldDisplayItem::walk_set( 'html', $d->fields ) );
|
68 |
+
$social_fields = implode( '', WPBDP_ListingFieldDisplayItem::walk_set( 'html', $d->social ) );
|
69 |
+
|
70 |
+
// images
|
71 |
+
$thumbnail_id = wpbdp_listings_api()->get_thumbnail_id($post->ID);
|
72 |
+
$images = wpbdp_listings_api()->get_images($post->ID);
|
73 |
+
$extra_images = array();
|
74 |
+
|
75 |
+
if ( wpbdp_get_option( 'allow-images' ) ) {
|
76 |
+
foreach ($images as $img) {
|
77 |
+
// create thumbnail of correct size if needed (only in single view to avoid consuming server resources)
|
78 |
+
_wpbdp_resize_image_if_needed( $img->ID );
|
79 |
+
|
80 |
+
if ($img->ID == $thumbnail_id) continue;
|
81 |
+
|
82 |
+
$full_image_data = wp_get_attachment_image_src( $img->ID, 'wpbdp-large', false );
|
83 |
+
$full_image_url = $full_image_data[0];
|
84 |
+
|
85 |
+
$extra_images[] = sprintf('<a href="%s" class="thickbox" data-lightbox="wpbdpgal" rel="wpbdpgal" target="_blank">%s</a>',
|
86 |
+
$full_image_url,
|
87 |
+
wp_get_attachment_image( $img->ID, 'wpbdp-thumb', false, array(
|
88 |
+
'class' => 'wpbdp-thumbnail size-thumbnail',
|
89 |
+
'alt' => the_title(null, null, false),
|
90 |
+
'title' => the_title(null, null, false)
|
91 |
+
) ));
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
$vars = array(
|
96 |
+
'actions' => wpbdp_render('parts/listing-buttons', array('listing_id' => $post->ID, 'view' => 'single'), false),
|
97 |
+
'is_sticky' => $sticky_status == 'sticky',
|
98 |
+
'sticky_tag' => $sticky_tag,
|
99 |
+
'title' => get_the_title(),
|
100 |
+
'main_image' => wpbdp_get_option( 'allow-images' ) ? wpbdp_listing_thumbnail( null, 'link=picture&class=wpbdp-single-thumbnail' ) : '',
|
101 |
+
'listing_fields' => apply_filters('wpbdp_single_listing_fields', $listing_fields, $post->ID),
|
102 |
+
'fields' => $d->fields,
|
103 |
+
'listing_id' => $post->ID,
|
104 |
+
'extra_images' => $extra_images
|
105 |
+
);
|
106 |
+
$vars = apply_filters( 'wpbdp_listing_template_vars', $vars, $post->ID );
|
107 |
+
$vars = apply_filters( 'wpbdp_single_template_vars', $vars, $post->ID );
|
108 |
+
|
109 |
+
$html .= wpbdp_render('businessdirectory-listing', $vars, true);
|
110 |
+
|
111 |
+
$social_fields = apply_filters('wpbdp_single_social_fields', $social_fields, $post->ID);
|
112 |
+
if ($social_fields)
|
113 |
+
$html .= '<div class="social-fields cf">' . $social_fields . '</div>';
|
114 |
+
|
115 |
+
$html .= apply_filters('wpbdp_listing_view_after', '', $post->ID, 'single');
|
116 |
+
$html .= wpbdp_capture_action('wpbdp_after_single_view', $post->ID);
|
117 |
+
|
118 |
+
if (wpbdp_get_option('show-comment-form')) {
|
119 |
+
$html .= '<div class="comments">';
|
120 |
+
|
121 |
+
ob_start();
|
122 |
+
comments_template(null, true);
|
123 |
+
$html .= ob_get_contents();
|
124 |
+
ob_end_clean();
|
125 |
+
|
126 |
+
$html .= '</div>';
|
127 |
+
}
|
128 |
+
|
129 |
+
$html .= '</div>';
|
130 |
+
|
131 |
+
return $html;
|
132 |
+
}
|
133 |
+
|
134 |
+
function _wpbdp_render_excerpt() {
|
135 |
+
global $post;
|
136 |
+
static $counter = 0;
|
137 |
+
|
138 |
+
$sticky_status = wpbdp_listings_api()->get_sticky_status($post->ID);
|
139 |
+
|
140 |
+
$html = '';
|
141 |
+
$html .= sprintf('<div id="wpbdp-listing-%d" class="wpbdp-listing excerpt wpbdp-listing-excerpt %s %s %s cf">',
|
142 |
+
$post->ID,
|
143 |
+
$sticky_status,
|
144 |
+
($counter & 1) ? 'odd': 'even',
|
145 |
+
apply_filters( 'wpbdp_excerpt_view_css', '', $post->ID ) );
|
146 |
+
$html .= wpbdp_capture_action('wpbdp_before_excerpt_view', $post->ID);
|
147 |
+
|
148 |
+
$d = WPBDP_ListingFieldDisplayItem::prepare_set( $post->ID, 'excerpt' );
|
149 |
+
$listing_fields = implode( '', WPBDP_ListingFieldDisplayItem::walk_set( 'html', $d->fields ) );
|
150 |
+
$social_fields = implode( '', WPBDP_ListingFieldDisplayItem::walk_set( 'html', $d->social ) );
|
151 |
+
|
152 |
+
|
153 |
+
$vars = array(
|
154 |
+
'is_sticky' => $sticky_status == 'sticky',
|
155 |
+
'thumbnail' => ( wpbdp_get_option( 'allow-images' ) && wpbdp_get_option( 'show-thumbnail' ) ) ? wpbdp_listing_thumbnail( null, 'link=listing&class=wpbdmthumbs wpbdp-excerpt-thumbnail' ) : '',
|
156 |
+
'title' => get_the_title(),
|
157 |
+
'listing_fields' => apply_filters('wpbdp_excerpt_listing_fields', $listing_fields, $post->ID),
|
158 |
+
'fields' => $d->fields,
|
159 |
+
'listing_id' => $post->ID
|
160 |
+
);
|
161 |
+
$vars = apply_filters( 'wpbdp_listing_template_vars', $vars, $post->ID );
|
162 |
+
$vars = apply_filters( 'wpbdp_excerpt_template_vars', $vars, $post->ID );
|
163 |
+
|
164 |
+
$html .= wpbdp_render('businessdirectory-excerpt', $vars, true);
|
165 |
+
|
166 |
+
$social_fields = apply_filters('wpbdp_excerpt_social_fields', $social_fields, $post->ID);
|
167 |
+
if ($social_fields)
|
168 |
+
$html .= '<div class="social-fields cf">' . $social_fields . '</div>';
|
169 |
+
|
170 |
+
$html .= wpbdp_capture_action('wpbdp_after_excerpt_view', $post->ID);
|
171 |
+
$html .= wpbdp_render('parts/listing-buttons', array('listing_id' => $post->ID, 'view' => 'excerpt'), false);
|
172 |
+
$html .= '</div>';
|
173 |
+
|
174 |
+
$counter++;
|
175 |
+
|
176 |
+
return $html;
|
177 |
+
}
|
178 |
+
|
179 |
+
function wpbdp_latest_listings($n=10, $before='<ul>', $after='</ul>', $before_item='<li>', $after_item = '</li>') {
|
180 |
+
$n = max(intval($n), 0);
|
181 |
+
|
182 |
+
$posts = get_posts(array(
|
183 |
+
'post_type' => WPBDP_POST_TYPE,
|
184 |
+
'post_status' => 'publish',
|
185 |
+
'numberposts' => $n,
|
186 |
+
'orderby' => 'date'
|
187 |
+
));
|
188 |
+
|
189 |
+
$html = '';
|
190 |
+
|
191 |
+
$html .= $before;
|
192 |
+
|
193 |
+
foreach ($posts as $post) {
|
194 |
+
$html .= $before_item;
|
195 |
+
$html .= sprintf('<a href="%s">%s</a>', get_permalink($post->ID), get_the_title($post->ID));
|
196 |
+
$html .= $after_item;
|
197 |
+
}
|
198 |
+
|
199 |
+
$html .= $after;
|
200 |
+
|
201 |
+
return $html;
|
202 |
+
}
|
core/templates-ui.php
ADDED
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* UI Functions to be called from templates.
|
4 |
+
*/
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Returns a list of directory categories using the configured directory settings.
|
8 |
+
* The list is actually produced by {@link wpbdp_list_categories()}.
|
9 |
+
* @return string HTML output.
|
10 |
+
* @uses wpbdp_list_categories().
|
11 |
+
*/
|
12 |
+
function wpbdp_directory_categories() {
|
13 |
+
$html = wpbdp_list_categories( array(
|
14 |
+
'hide_empty' => wpbdp_get_option( 'hide-empty-categories' ),
|
15 |
+
'parent_only' => wpbdp_get_option( 'show-only-parent-categories' )
|
16 |
+
) );
|
17 |
+
|
18 |
+
return apply_filters( 'wpbdp_main_categories', $html );
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Identical to {@link wpbdp_directory_categories()}, except the output is printed instead of returned.
|
23 |
+
* @uses wpbdp_directory_categories().
|
24 |
+
*/
|
25 |
+
function wpbdp_the_directory_categories() {
|
26 |
+
echo wpbdp_directory_categories();
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @since 2.3
|
31 |
+
* @access private
|
32 |
+
*/
|
33 |
+
function _wpbdp_padded_count( &$term ) {
|
34 |
+
global $wpdb;
|
35 |
+
|
36 |
+
$count = intval( wp_cache_get( 'term-padded-count-' . $term->term_id ,'wpbdp', false, $found ) );
|
37 |
+
|
38 |
+
if ( ! $count && ! $found ) {
|
39 |
+
$tree_ids = array_merge( array( $term->term_id ), get_term_children( $term->term_id, WPBDP_CATEGORY_TAX ) );
|
40 |
+
$tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id IN (" . implode( ',', $tree_ids ) . ") AND taxonomy = %s", WPBDP_CATEGORY_TAX ) );
|
41 |
+
|
42 |
+
$query = $wpdb->prepare( "SELECT COUNT(DISTINCT r.object_id) FROM {$wpdb->term_relationships} r INNER JOIN {$wpdb->posts} p ON p.ID = r.object_id WHERE p.post_status = %s and p.post_type = %s AND term_taxonomy_id IN (" . implode( ',', $tt_ids ) . ")", 'publish', WPBDP_POST_TYPE );
|
43 |
+
$count = apply_filters( '_wpbdp_padded_count', intval( $wpdb->get_var( $query ) ), $term );
|
44 |
+
}
|
45 |
+
|
46 |
+
$term->count = $count;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* @since 2.3
|
51 |
+
* @access private
|
52 |
+
*/
|
53 |
+
function _wpbdp_list_categories_walk( $parent=0, $depth=0, $args ) {
|
54 |
+
$term_ids = get_terms( WPBDP_CATEGORY_TAX,
|
55 |
+
array( 'orderby' => $args['orderby'],
|
56 |
+
'order' => $args['order'],
|
57 |
+
'hide_empty' => false,
|
58 |
+
'pad_counts' => false,
|
59 |
+
'parent' => is_object( $args['parent'] ) ? $args['parent']->term_id : intval( $args['parent'] ),
|
60 |
+
'fields' => 'ids' )
|
61 |
+
);
|
62 |
+
|
63 |
+
$terms = array();
|
64 |
+
foreach ( $term_ids as $term_id ) {
|
65 |
+
$t = get_term( $term_id, WPBDP_CATEGORY_TAX );
|
66 |
+
// 'pad_counts' doesn't work because of WP bug #15626 (see http://core.trac.wordpress.org/ticket/15626).
|
67 |
+
// we need a workaround until the bug is fixed.
|
68 |
+
_wpbdp_padded_count( $t );
|
69 |
+
|
70 |
+
$terms[] = $t;
|
71 |
+
}
|
72 |
+
|
73 |
+
// filter empty terms
|
74 |
+
if ( $args['hide_empty'] ) {
|
75 |
+
$terms = array_filter( $terms, create_function( '$x', 'return $x->count > 0;' ) );
|
76 |
+
}
|
77 |
+
|
78 |
+
$html = '';
|
79 |
+
|
80 |
+
if ( !$terms && $depth == 0 ) {
|
81 |
+
if ( $args['no_items_msg'] )
|
82 |
+
$html .= '<p>' . $args['no_items_msg'] . '</p>';
|
83 |
+
return $html;
|
84 |
+
}
|
85 |
+
|
86 |
+
if ( $depth > 0 ) {
|
87 |
+
$html .= str_repeat( "\t", $depth );
|
88 |
+
|
89 |
+
if ( apply_filters( 'wpbdp_categories_list_anidate_children', true ) && $terms ) {
|
90 |
+
$html .= '<ul class="children">';
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
foreach ( $terms as &$term ) {
|
95 |
+
$html .= '<li class="cat-item cat-item-' . $term->term_id . ' ' . apply_filters( 'wpbdp_categories_list_item_css', '', $term ) . ' ' . ( $depth > 0 ? 'subcat' : '' ) . '">';
|
96 |
+
|
97 |
+
$item_html = '';
|
98 |
+
$item_html .= '<a href="' . esc_url( get_term_link( $term ) ) . '" ';
|
99 |
+
$item_html .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $term->description, $term ) ) ) . '" class="category-label" >';
|
100 |
+
$item_html .= esc_attr( $term->name );
|
101 |
+
$item_html .= '</a>';
|
102 |
+
|
103 |
+
if ( $args['show_count'] ) {
|
104 |
+
$count_str = ' (' . intval( $term->count ) . ')';
|
105 |
+
$count_str = apply_filters( 'wpbdp_categories_item_count_str', $count_str, $term );
|
106 |
+
$item_html .= $count_str;
|
107 |
+
}
|
108 |
+
|
109 |
+
$item_html = apply_filters( 'wpbdp_categories_list_item', $item_html, $term );
|
110 |
+
$html .= $item_html;
|
111 |
+
|
112 |
+
if ( !$args['parent_only'] ) {
|
113 |
+
$args['parent'] = $term->term_id;
|
114 |
+
if ( $subcats = _wpbdp_list_categories_walk( $term->term_id, $depth + 1, $args ) )
|
115 |
+
$html .= $subcats;
|
116 |
+
}
|
117 |
+
|
118 |
+
$html .= '</li>';
|
119 |
+
}
|
120 |
+
|
121 |
+
if ( $depth > 0 ) {
|
122 |
+
if ( apply_filters( 'wpbdp_categories_list_anidate_children', true ) && $terms ) {
|
123 |
+
$html .= '</ul>';
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
return $html;
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Produces a list of directory categories following some configuration settings that are overridable.
|
132 |
+
*
|
133 |
+
* The list of arguments is below:
|
134 |
+
* 'parent' (int|object) - Parent directory category or category ID.
|
135 |
+
* 'orderby' (string) default is taken from BD settings - What column to use for ordering the categories.
|
136 |
+
* 'order' (string) default is taken from BD settings - What direction to order categories.
|
137 |
+
* 'show_count' (boolean) default is taken from BD settings - Whether to show how many listings are in the category.
|
138 |
+
* 'hide_empty' (boolean) default is False - Whether to hide empty categories or not.
|
139 |
+
* 'parent_only' (boolean) default is False - Whether to show only direct childs of 'parent' or make a recursive list.
|
140 |
+
* 'echo' (boolean) default is False - If True, the list will be printed in addition to returned by this function.
|
141 |
+
* 'no_items_msg' (string) default is "No listing categories found." - Message to display when no categories are found.
|
142 |
+
*
|
143 |
+
* @param string|array $args array of arguments to be used while creating the list.
|
144 |
+
* @return string HTML output.
|
145 |
+
* @since 2.3
|
146 |
+
* @see wpbdp_directory_categories()
|
147 |
+
*/
|
148 |
+
function wpbdp_list_categories( $args=array() ) {
|
149 |
+
$args = wp_parse_args( $args, array(
|
150 |
+
'parent' => null,
|
151 |
+
'echo' => false,
|
152 |
+
'orderby' => wpbdp_get_option( 'categories-order-by' ),
|
153 |
+
'order' => wpbdp_get_option( 'categories-sort' ),
|
154 |
+
'show_count' => wpbdp_get_option('show-category-post-count'),
|
155 |
+
'hide_empty' => false,
|
156 |
+
'parent_only' => false,
|
157 |
+
'parent' => 0,
|
158 |
+
'no_items_msg' => _x( 'No listing categories found.', 'templates', 'WPBDM' )
|
159 |
+
) );
|
160 |
+
|
161 |
+
$html = '';
|
162 |
+
|
163 |
+
if ( $categories = _wpbdp_list_categories_walk( 0, 0, $args ) ) {
|
164 |
+
$html .= '<ul class="wpbdp-categories ' . apply_filters( 'wpbdp_categories_list_css', '' ) . '">';
|
165 |
+
$html .= $categories;
|
166 |
+
$html .= '</ul>';
|
167 |
+
}
|
168 |
+
|
169 |
+
$html = apply_filters( 'wpbdp_categories_list', $html );
|
170 |
+
|
171 |
+
if ( $args['echo'] )
|
172 |
+
echo $html;
|
173 |
+
|
174 |
+
return $html;
|
175 |
+
}
|
176 |
+
|
177 |
+
function wpbdp_main_links() {
|
178 |
+
$html = '';
|
179 |
+
|
180 |
+
if (wpbdp_get_option('show-submit-listing')) {
|
181 |
+
$html .= sprintf('<input id="wpbdp-bar-submit-listing-button" type="button" value="%s" onclick="window.location.href = \'%s\'" class="button" />',
|
182 |
+
__('Submit A Listing', 'WPBDM'),
|
183 |
+
wpbdp_get_page_link('add-listing'));
|
184 |
+
/* $html .= sprintf('<a href="%s">%s</a>',
|
185 |
+
wpbdp_get_page_link('add-listing'),
|
186 |
+
__('Submit A Listing', 'WPBDM'));*/
|
187 |
+
}
|
188 |
+
|
189 |
+
if (wpbdp_get_option('show-view-listings')) {
|
190 |
+
$html .= sprintf('<input id="wpbdp-bar-view-listings-button" type="button" value="%s" onclick="window.location.href = \'%s\'" class="button" />',
|
191 |
+
__('View Listings', 'WPBDM'),
|
192 |
+
wpbdp_get_page_link('view-listings'));
|
193 |
+
/* $html .= sprintf('<a href="%s">%s</a>',
|
194 |
+
wpbdp_get_page_link('view-listings'),
|
195 |
+
__('View Listings', 'WPBDM')
|
196 |
+
);*/
|
197 |
+
}
|
198 |
+
|
199 |
+
if (wpbdp_get_option('show-directory-button')) {
|
200 |
+
$html .= sprintf( '<input id="wpbdp-bar-show-directory-button" type="button" value="%s" onclick="window.location.href = \'%s\'" class="button" />',
|
201 |
+
__('Directory', 'WPBDM'),
|
202 |
+
wpbdp_get_page_link('main') );
|
203 |
+
/* $html .= sprintf('<a href="%s">%s</a>',
|
204 |
+
wpbdp_get_page_link('main'),
|
205 |
+
__('Directory', 'WPBDM')
|
206 |
+
);*/
|
207 |
+
}
|
208 |
+
|
209 |
+
if ( $html )
|
210 |
+
$html = '<div class="wpbdp-main-links">' . apply_filters( 'wpbdp_main_links', $html ) . '</div>';
|
211 |
+
|
212 |
+
return $html;
|
213 |
+
}
|
214 |
+
|
215 |
+
function wpbdp_the_main_links() {
|
216 |
+
echo wpbdp_main_links();
|
217 |
+
}
|
218 |
+
|
219 |
+
function wpbdp_search_form() {
|
220 |
+
$html = '';
|
221 |
+
$html .= sprintf('<form id="wpbdmsearchform" action="" method="GET" class="wpbdp-search-form">
|
222 |
+
<input type="hidden" name="action" value="search" />
|
223 |
+
<input type="hidden" name="page_id" value="%d" />
|
224 |
+
<input type="hidden" name="dosrch" value="1" />',
|
225 |
+
wpbdp_get_page_id('main'));
|
226 |
+
$html .= '<input id="intextbox" maxlength="150" name="q" size="20" type="text" value="" />';
|
227 |
+
$html .= sprintf('<input id="wpbdmsearchsubmit" class="submit" type="submit" value="%s" />',
|
228 |
+
_x('Search Listings', 'templates', 'WPBDM'));
|
229 |
+
$html .= sprintf('<a href="%s" class="advanced-search-link">%s</a>',
|
230 |
+
add_query_arg('action', 'search', wpbdp_get_page_link('main')),
|
231 |
+
_x('Advanced Search', 'templates', 'WPBDM'));
|
232 |
+
$html .= '</form>';
|
233 |
+
|
234 |
+
return $html;
|
235 |
+
}
|
236 |
+
|
237 |
+
function wpbdp_the_search_form() {
|
238 |
+
if (wpbdp_get_option('show-search-listings'))
|
239 |
+
echo wpbdp_search_form();
|
240 |
+
}
|
241 |
+
|
242 |
+
function wpbdp_the_listing_excerpt() {
|
243 |
+
echo wpbdp_render_listing(null, 'excerpt');
|
244 |
+
}
|
245 |
+
|
246 |
+
function wpbdp_listing_sort_options() {
|
247 |
+
$sort_options = array();
|
248 |
+
$sort_options = apply_filters('wpbdp_listing_sort_options', $sort_options);
|
249 |
+
|
250 |
+
if (!$sort_options)
|
251 |
+
return '';
|
252 |
+
|
253 |
+
$current_sort = wpbdp_get_current_sort_option();
|
254 |
+
|
255 |
+
$html = '';
|
256 |
+
$html .= '<div class="wpbdp-listings-sort-options">';
|
257 |
+
$html .= _x('Sort By:', 'templates sort', 'WPBDM') . ' ';
|
258 |
+
|
259 |
+
foreach ($sort_options as $id => $option) {
|
260 |
+
$default_order = isset( $option[2] ) && !empty( $option[2] ) ? strtoupper( $option[2] ) : 'ASC';
|
261 |
+
|
262 |
+
$html .= sprintf('<span class="%s %s"><a href="%s" title="%s">%s</a> %s</span>',
|
263 |
+
$id,
|
264 |
+
($current_sort && $current_sort->option == $id) ? 'current': '',
|
265 |
+
($current_sort && $current_sort->option == $id) ? add_query_arg('wpbdp_sort', ($current_sort->order == 'ASC' ? '-' : '') . $id) : add_query_arg('wpbdp_sort', ( $default_order == 'DESC' ? '-' : '' ) . $id ),
|
266 |
+
isset( $option[1] ) && !empty( $option[1] ) ? esc_attr( $option[1] ) : esc_attr( $option[0] ),
|
267 |
+
$option[0],
|
268 |
+
($current_sort && $current_sort->option == $id) ? ($current_sort->order == 'ASC' ? '↑' : '↓') : ( $default_order == 'DESC' ? '↓' : '↑' )
|
269 |
+
);
|
270 |
+
$html .= ' | ';
|
271 |
+
}
|
272 |
+
$html = substr($html, 0, -3);
|
273 |
+
$html .= '<br />';
|
274 |
+
|
275 |
+
if ($current_sort)
|
276 |
+
$html .= sprintf( '(<a href="%s" class="reset">%s</a>)', remove_query_arg( 'wpbdp_sort' ), _x( 'Reset', 'sort', 'WPBDM' ) );
|
277 |
+
$html .= '</div>';
|
278 |
+
|
279 |
+
return $html;
|
280 |
+
}
|
281 |
+
|
282 |
+
function wpbdp_the_listing_sort_options() {
|
283 |
+
echo wpbdp_listing_sort_options();
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* @deprecated since 2.2.1
|
288 |
+
*/
|
289 |
+
function wpbdp_bar($parts=array()) {
|
290 |
+
$parts = wp_parse_args($parts, array(
|
291 |
+
'links' => true,
|
292 |
+
'search' => false
|
293 |
+
));
|
294 |
+
|
295 |
+
$html = '<div class="wpbdp-bar cf">';
|
296 |
+
$html .= apply_filters('wpbdp_bar_before', '', $parts);
|
297 |
+
|
298 |
+
if ($parts['links'])
|
299 |
+
$html .= wpbdp_main_links();
|
300 |
+
if ($parts['search'])
|
301 |
+
$html .= wpbdp_search_form();
|
302 |
+
|
303 |
+
$html .= apply_filters('wpbdp_bar_after', '', $parts);
|
304 |
+
$html .= '</div>';
|
305 |
+
|
306 |
+
return $html;
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* @deprecated since 2.2.1
|
311 |
+
*/
|
312 |
+
function wpbdp_the_bar($parts=array()) {
|
313 |
+
echo wpbdp_bar($parts);
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Displays the listing main image.
|
318 |
+
* @since 2.3
|
319 |
+
*/
|
320 |
+
function wpbdp_listing_thumbnail( $listing_id=null, $args=array() ) {
|
321 |
+
if ( !$listing_id ) $listing_id = get_the_ID();
|
322 |
+
|
323 |
+
$args = wp_parse_args( $args, array(
|
324 |
+
'link' => 'picture',
|
325 |
+
'class' => '',
|
326 |
+
'echo' => false,
|
327 |
+
) );
|
328 |
+
|
329 |
+
$main_image = false;
|
330 |
+
$image_img = '';
|
331 |
+
$image_link = '';
|
332 |
+
$image_classes = 'wpbdp-thumbnail attachment-wpbdp-thumb ' . $args['class'];
|
333 |
+
|
334 |
+
if ( $thumbnail_id = wpbdp_listings_api()->get_thumbnail_id( $listing_id ) ) {
|
335 |
+
$main_image = get_post( $thumbnail_id );
|
336 |
+
} else {
|
337 |
+
$images = wpbdp_listings_api()->get_images( $listing_id );
|
338 |
+
|
339 |
+
if ( $images )
|
340 |
+
$main_image = $images[0];
|
341 |
+
}
|
342 |
+
|
343 |
+
if ( !$main_image && function_exists( 'has_post_thumbnail' ) && has_post_thumbnail( $listing_id ) ) {
|
344 |
+
$image_img = get_the_post_thumbnail( $listing_id, 'wpbdp-thumb' );
|
345 |
+
} elseif( !$main_image && wpbdp_get_option( 'use-default-picture' ) ) {
|
346 |
+
$image_img = sprintf( '<img src="%s" alt="%s" title="%s" border="0" width="%d" class="%s" />',
|
347 |
+
WPBDP_URL . 'core/images/default-image-big.gif',
|
348 |
+
get_the_title( $listing_id ),
|
349 |
+
get_the_title( $listing_id ),
|
350 |
+
wpbdp_get_option( 'thumbnail-width' ),
|
351 |
+
$image_classes
|
352 |
+
);
|
353 |
+
$image_link = $args['link'] == 'picture' ? WPBDP_URL . 'core/images/default-image-big.gif' : '';
|
354 |
+
} elseif ( $main_image ) {
|
355 |
+
$image_img = wp_get_attachment_image( $main_image->ID,
|
356 |
+
'wpbdp-thumb',
|
357 |
+
false,
|
358 |
+
array(
|
359 |
+
'alt' => get_the_title( $listing_id ),
|
360 |
+
'title' => get_the_title( $listing_id ),
|
361 |
+
'class' => $image_classes
|
362 |
+
)
|
363 |
+
);
|
364 |
+
|
365 |
+
if ( $args['link'] == 'picture' ) {
|
366 |
+
$full_image_data = wp_get_attachment_image_src( $main_image->ID, 'wpbdp-large' );
|
367 |
+
$image_link = $full_image_data[0];
|
368 |
+
}
|
369 |
+
|
370 |
+
}
|
371 |
+
|
372 |
+
if ( !$image_link && $args['link'] == 'listing' )
|
373 |
+
$image_link = get_permalink( $listing_id );
|
374 |
+
|
375 |
+
if ( $image_img ) {
|
376 |
+
if ( !$image_link ) {
|
377 |
+
return $image_img;
|
378 |
+
} else {
|
379 |
+
return sprintf( '<div class="listing-thumbnail"><a href="%s" class="%s" %s>%s</a></div>',
|
380 |
+
$image_link,
|
381 |
+
$args['link'] == 'picture' ? 'thickbox' : '',
|
382 |
+
$args['link'] == 'picture' ? 'data-lightbox="wpbdpgal" rel="wpbdpgal"' : '',
|
383 |
+
$image_img );
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
return '' ;
|
388 |
+
}
|
389 |
+
|
390 |
+
|
391 |
+
class WPBDP_ListingFieldDisplayItem {
|
392 |
+
private $listing_id = 0;
|
393 |
+
private $display = '';
|
394 |
+
|
395 |
+
private $html_ = '';
|
396 |
+
private $html_value_ = '';
|
397 |
+
private $value_ = null;
|
398 |
+
|
399 |
+
public $id = 0;
|
400 |
+
public $field;
|
401 |
+
|
402 |
+
public function __construct( &$field, $listing_id = 0, $display ) {
|
403 |
+
$this->field = $field;
|
404 |
+
$this->id = $this->field->get_id();
|
405 |
+
$this->listing_id = $listing_id;
|
406 |
+
$this->display = $display;
|
407 |
+
}
|
408 |
+
|
409 |
+
public function __get( $key ) {
|
410 |
+
switch ( $key ) {
|
411 |
+
case 'html':
|
412 |
+
if ( $this->html_ )
|
413 |
+
return $this->html_;
|
414 |
+
|
415 |
+
$this->html_ = $this->field->display( $this->listing_id, $this->display );
|
416 |
+
return $this->html_;
|
417 |
+
break;
|
418 |
+
|
419 |
+
case 'html_value':
|
420 |
+
if ( $this->html_value_ )
|
421 |
+
return $this->html_value_;
|
422 |
+
|
423 |
+
$this->html_value_ = $this->field->html_value( $this->listing_id );
|
424 |
+
return $this->html_value_;
|
425 |
+
break;
|
426 |
+
|
427 |
+
case 'value':
|
428 |
+
if ( $this->value_ )
|
429 |
+
return $this->value_;
|
430 |
+
|
431 |
+
$this->value_ = $this->field->value( $this->listing_id );
|
432 |
+
return $this->value_;
|
433 |
+
break;
|
434 |
+
|
435 |
+
default:
|
436 |
+
break;
|
437 |
+
}
|
438 |
+
}
|
439 |
+
|
440 |
+
public static function prepare_set( $listing_id, $display ) {
|
441 |
+
$res = (object) array( 'fields' => array(), 'social' => array() );
|
442 |
+
|
443 |
+
$form_fields = wpbdp_get_form_fields();
|
444 |
+
$form_fields = apply_filters_ref_array( 'wpbdp_render_listing_fields', array( &$form_fields, $listing_id ) );
|
445 |
+
|
446 |
+
foreach ( $form_fields as &$f ) {
|
447 |
+
if ( ! $f->display_in( $display ) )
|
448 |
+
continue;
|
449 |
+
|
450 |
+
if ( $f->display_in( 'social' ) )
|
451 |
+
$res->social[ $f->get_id() ] = new self( $f, $listing_id, 'social' );
|
452 |
+
else
|
453 |
+
$res->fields[ $f->get_id() ] = new self( $f, $listing_id, $display );
|
454 |
+
}
|
455 |
+
|
456 |
+
return $res;
|
457 |
+
}
|
458 |
+
|
459 |
+
public static function walk_set( $prop, $fields = array() ) {
|
460 |
+
$res = array();
|
461 |
+
|
462 |
+
foreach ( $fields as $k => &$f )
|
463 |
+
$res[ $k ] = $f->{$prop};
|
464 |
+
|
465 |
+
return $res;
|
466 |
+
}
|
467 |
+
}
|
core/utils.php
ADDED
@@ -0,0 +1,495 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/debugging.php' );
|
3 |
+
require_once( WPBDP_PATH . 'core/class-email.php' );
|
4 |
+
require_once( WPBDP_PATH . 'core/class-ajax-response.php' );
|
5 |
+
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Restructures multidimensional $_FILES arrays into one key-based array per file.
|
9 |
+
* Single-file arrays are returned as an array of one item for consistency.
|
10 |
+
*
|
11 |
+
* @since 3.4
|
12 |
+
*
|
13 |
+
* @param array $_FILES array
|
14 |
+
* @return array
|
15 |
+
*/
|
16 |
+
function wpbdp_flatten_files_array( $files = array() ) {
|
17 |
+
if ( ! isset( $files['tmp_name'] ) )
|
18 |
+
return $files;
|
19 |
+
|
20 |
+
if ( ! is_array( $files['tmp_name'] ) )
|
21 |
+
return array( $files );
|
22 |
+
|
23 |
+
$res = array();
|
24 |
+
foreach ( $files as $k1 => $v1 ) {
|
25 |
+
foreach ( $v1 as $k2 => $v2 ) {
|
26 |
+
$res[ $k2 ][ $k1 ] = $v2;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
return $res;
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Returns properties and array values from objects or arrays, resp.
|
36 |
+
*
|
37 |
+
* @param array|object $dict
|
38 |
+
* @param string $key Property name or array key.
|
39 |
+
* @param mixed $default Optional. Defaults to `false`.
|
40 |
+
*
|
41 |
+
*/
|
42 |
+
function wpbdp_getv($dict, $key, $default=false) {
|
43 |
+
$_dict = is_object($dict) ? (array) $dict : $dict;
|
44 |
+
|
45 |
+
if (is_array($_dict) && isset($_dict[$key]))
|
46 |
+
return $_dict[$key];
|
47 |
+
|
48 |
+
return $default;
|
49 |
+
}
|
50 |
+
|
51 |
+
function wpbdp_capture_action($hook) {
|
52 |
+
$output = '';
|
53 |
+
|
54 |
+
$args = func_get_args();
|
55 |
+
if (count($args) > 1) {
|
56 |
+
$args = array_slice($args, 1);
|
57 |
+
} else {
|
58 |
+
$args = array();
|
59 |
+
}
|
60 |
+
|
61 |
+
ob_start();
|
62 |
+
do_action_ref_array($hook, $args);
|
63 |
+
$output = ob_get_contents();
|
64 |
+
ob_end_clean();
|
65 |
+
|
66 |
+
return $output;
|
67 |
+
}
|
68 |
+
|
69 |
+
function wpbdp_capture_action_array($hook, $args=array()) {
|
70 |
+
$output = '';
|
71 |
+
|
72 |
+
ob_start();
|
73 |
+
do_action_ref_array($hook, $args);
|
74 |
+
$output = ob_get_contents();
|
75 |
+
ob_end_clean();
|
76 |
+
|
77 |
+
return $output;
|
78 |
+
}
|
79 |
+
|
80 |
+
function wpbdp_php_ini_size_to_bytes( $val ) {
|
81 |
+
$val = trim( $val );
|
82 |
+
$size = intval( $val );
|
83 |
+
$unit = strtoupper( $val[strlen($val) - 1] );
|
84 |
+
|
85 |
+
switch ( $unit ) {
|
86 |
+
case 'G':
|
87 |
+
$size *= 1024;
|
88 |
+
case 'M':
|
89 |
+
$size *= 1024;
|
90 |
+
case 'K':
|
91 |
+
$size *= 1024;
|
92 |
+
}
|
93 |
+
|
94 |
+
return $size;
|
95 |
+
}
|
96 |
+
|
97 |
+
function wpbdp_media_upload_check_env( &$error ) {
|
98 |
+
if ( empty( $_FILES ) && empty( $_POST ) && isset( $_SERVER['REQUEST_METHOD'] ) &&
|
99 |
+
strtolower( $_SERVER['REQUEST_METHOD'] ) == 'post' ) {
|
100 |
+
$post_max = wpbdp_php_ini_size_to_bytes( ini_get( 'post_max_size' ) );
|
101 |
+
$posted_size = intval( $_SERVER['CONTENT_LENGTH'] );
|
102 |
+
|
103 |
+
if ( $posted_size > $post_max ) {
|
104 |
+
$error = _x( 'POSTed data exceeds PHP config. maximum. See "post_max_size" directive.', 'utils', 'WPBDM' );
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
return true;
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* @since 2.1.6
|
114 |
+
*/
|
115 |
+
function wpbdp_media_upload($file, $use_media_library=true, $check_image=false, $constraints=array(), &$error_msg=null) {
|
116 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
117 |
+
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
118 |
+
|
119 |
+
$constraints = array_merge( array(
|
120 |
+
'image' => false,
|
121 |
+
'max-size' => 0,
|
122 |
+
'mimetypes' => null
|
123 |
+
), $constraints );
|
124 |
+
|
125 |
+
if ($file['error'] == 0) {
|
126 |
+
if ($constraints['max-size'] > 0 && $file['size'] > $constraints['max-size'] ) {
|
127 |
+
$error_msg = sprintf( _x( 'File size (%s) exceeds maximum file size of %s', 'utils', 'WPBDM' ),
|
128 |
+
size_format ($file['size'], 2),
|
129 |
+
size_format ($constraints['max-size'], 2)
|
130 |
+
);
|
131 |
+
return false;
|
132 |
+
}
|
133 |
+
|
134 |
+
if ( is_array( $constraints['mimetypes'] ) ) {
|
135 |
+
if ( !in_array( strtolower( $file['type'] ), $constraints['mimetypes'] ) ) {
|
136 |
+
$error_msg = sprintf( _x( 'File type "%s" is not allowed', 'utils', 'WPBDM' ), $file['type'] );
|
137 |
+
return false;
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
// We do not accept TIFF format. Compatibility issues.
|
142 |
+
if ( in_array( strtolower( $file['type'] ), array('image/tiff') ) ) {
|
143 |
+
$error_msg = sprintf( _x( 'File type "%s" is not allowed', 'utils', 'WPBDM' ), $file['type'] );
|
144 |
+
return false;
|
145 |
+
}
|
146 |
+
|
147 |
+
$upload = wp_handle_upload( $file, array('test_form' => FALSE) );
|
148 |
+
|
149 |
+
if( ! $upload || ! is_array( $upload ) || isset( $upload['error'] ) ) {
|
150 |
+
$error_msg = isset( $upload['error'] ) ? $upload['error'] : _x( 'Unkown error while uploading file.', 'utils', 'WPBDM' );
|
151 |
+
return false;
|
152 |
+
}
|
153 |
+
|
154 |
+
if ( !$use_media_library )
|
155 |
+
return $upload;
|
156 |
+
|
157 |
+
if ( $attachment_id = wp_insert_attachment(array(
|
158 |
+
'post_mime_type' => $upload['type'],
|
159 |
+
'post_title' => preg_replace('/\.[^.]+$/', '', basename($upload['file'])),
|
160 |
+
'post_content' => '',
|
161 |
+
'post_status' => 'inherit'
|
162 |
+
), $upload['file']) ) {
|
163 |
+
$attach_metadata = wp_generate_attachment_metadata( $attachment_id, $upload['file'] );
|
164 |
+
wp_update_attachment_metadata( $attachment_id, $attach_metadata );
|
165 |
+
|
166 |
+
if ( $check_image && !wp_attachment_is_image( $attachment_id ) ) {
|
167 |
+
wp_delete_attachment( $attachment_id, true );
|
168 |
+
|
169 |
+
$error_msg = _x('Uploaded file is not an image', 'utils', 'WPBDM');
|
170 |
+
return false;
|
171 |
+
}
|
172 |
+
|
173 |
+
return $attachment_id;
|
174 |
+
}
|
175 |
+
} else {
|
176 |
+
$error_msg = _x('Error while uploading file', 'utils', 'WPBDM');
|
177 |
+
}
|
178 |
+
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Returns the domain used in the current request, optionally stripping
|
184 |
+
* the www part of the domain.
|
185 |
+
*
|
186 |
+
* @since 2.1.5
|
187 |
+
* @param $www boolean true to include the 'www' part,
|
188 |
+
* false to attempt to strip it.
|
189 |
+
*/
|
190 |
+
function wpbdp_get_current_domain($www=true, $prefix='') {
|
191 |
+
$domain = wpbdp_getv($_SERVER, 'HTTP_HOST', '');
|
192 |
+
if (empty($domain)) {
|
193 |
+
$domain = wpbdp_getv($_SERVER, 'SERVER_NAME', '');
|
194 |
+
}
|
195 |
+
|
196 |
+
if (!$www && substr($domain, 0, 4) === 'www.') {
|
197 |
+
$domain = $prefix . substr($domain, 4);
|
198 |
+
}
|
199 |
+
|
200 |
+
return $domain;
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Bulds WordPress ajax URL using the same domain used in the current request.
|
205 |
+
*
|
206 |
+
* @since 2.1.5
|
207 |
+
*/
|
208 |
+
function wpbdp_ajaxurl($overwrite=false) {
|
209 |
+
static $ajaxurl = false;
|
210 |
+
|
211 |
+
if ($overwrite || $ajaxurl === false) {
|
212 |
+
$url = admin_url('admin-ajax.php');
|
213 |
+
$parts = parse_url($url);
|
214 |
+
|
215 |
+
$domain = wpbdp_get_current_domain();
|
216 |
+
|
217 |
+
// Since $domain already contains the port remove it.
|
218 |
+
if ( isset( $parts['port'] ) && $parts['port'] )
|
219 |
+
$domain = str_replace( ':' . $parts['port'], '', $domain );
|
220 |
+
|
221 |
+
$ajaxurl = str_replace($parts['host'], $domain, $url);
|
222 |
+
}
|
223 |
+
|
224 |
+
return $ajaxurl;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Removes a value from an array.
|
229 |
+
* @since 2.3
|
230 |
+
*/
|
231 |
+
function wpbdp_array_remove_value( &$array_, &$value_ ) {
|
232 |
+
$key = array_search( $value_, $array_ );
|
233 |
+
|
234 |
+
if ( $key !== false ) {
|
235 |
+
unset( $array_[$key] );
|
236 |
+
}
|
237 |
+
|
238 |
+
return true;
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Checks if a given string starts with another string.
|
243 |
+
* @param string $str the string to be searched
|
244 |
+
* @param string $prefix the prefix to search for
|
245 |
+
* @return TRUE if $str starts with $prefix or FALSE otherwise
|
246 |
+
* @since 3.0.3
|
247 |
+
*/
|
248 |
+
function wpbdp_starts_with( $str, $prefix, $case_sensitive=true ) {
|
249 |
+
if ( !$case_sensitive )
|
250 |
+
return stripos( $str, $prefix, 0 ) === 0;
|
251 |
+
|
252 |
+
return strpos( $str, $prefix, 0 ) === 0;
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* @since 3.1
|
257 |
+
*/
|
258 |
+
function wpbdp_format_time( $time=null, $format='mysql', $time_is_date=false ) {
|
259 |
+
// TODO: add more formats
|
260 |
+
switch ( $format ) {
|
261 |
+
case 'mysql':
|
262 |
+
return date( 'Y-m-d H:i:s', $time );
|
263 |
+
break;
|
264 |
+
default:
|
265 |
+
break;
|
266 |
+
}
|
267 |
+
|
268 |
+
return $time;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Returns the contents of a directory (ignoring . and .. special files).
|
273 |
+
* @param string $path a directory.
|
274 |
+
* @return array list of files within the directory.
|
275 |
+
* @since 3.3
|
276 |
+
*/
|
277 |
+
function wpbdp_scandir( $path ) {
|
278 |
+
if ( !is_dir( $path ) )
|
279 |
+
return array();
|
280 |
+
|
281 |
+
return array_diff( scandir( $path ), array( '.', '..' ) );
|
282 |
+
}
|
283 |
+
|
284 |
+
/**
|
285 |
+
* Recursively deletes a directory.
|
286 |
+
* @param string $path a directory.
|
287 |
+
* @since 3.3
|
288 |
+
*/
|
289 |
+
function wpbdp_rrmdir( $path ) {
|
290 |
+
if ( !is_dir( $path ) )
|
291 |
+
return;
|
292 |
+
|
293 |
+
$files = wpbdp_scandir( $path );
|
294 |
+
|
295 |
+
foreach ( $files as &$f ) {
|
296 |
+
$filepath = rtrim( $path, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . ltrim( $f, DIRECTORY_SEPARATOR );
|
297 |
+
|
298 |
+
if ( is_dir( $filepath ) )
|
299 |
+
wpbdp_rrmdir( $filepath );
|
300 |
+
else
|
301 |
+
unlink( $filepath );
|
302 |
+
}
|
303 |
+
|
304 |
+
rmdir( $path );
|
305 |
+
}
|
306 |
+
|
307 |
+
/**
|
308 |
+
* Returns the name of a term.
|
309 |
+
* @param id|string $id_or_slug The term ID or slug (see `$field`).
|
310 |
+
* @param string $taxonomy Taxonomy name. Defaults to `WPBDP_CATEGORY_TAX` (BD's category taxonomy).
|
311 |
+
* @param string $field Field used for the term lookup. Defaults to "id".
|
312 |
+
* @param boolean $escape Whether to escape the name before returning or not. Defaults to `True`.
|
313 |
+
* @return string The term name (if found) or an empty string otherwise.
|
314 |
+
* @since 3.3
|
315 |
+
*/
|
316 |
+
function wpbdp_get_term_name( $id_or_slug, $taxonomy = WPBDP_CATEGORY_TAX, $field = 'id', $escape = true ) {
|
317 |
+
$term = get_term_by( $field,
|
318 |
+
'id' == $field ? intval( $id_or_slug ) : $id_or_slug,
|
319 |
+
$taxonomy );
|
320 |
+
|
321 |
+
if ( ! $term )
|
322 |
+
return '';
|
323 |
+
|
324 |
+
return $term->name;
|
325 |
+
}
|
326 |
+
|
327 |
+
function wpbdp_has_shortcode( &$content, $shortcode ) {
|
328 |
+
$check = has_shortcode( $content, $shortcode );
|
329 |
+
|
330 |
+
if ( ! $check ) {
|
331 |
+
// Sometimes has_shortcode() fails so we try another approach.
|
332 |
+
if ( false !== stripos( $content, '[' . $shortcode . ']' ) )
|
333 |
+
$check = true;
|
334 |
+
}
|
335 |
+
|
336 |
+
return $check;
|
337 |
+
}
|
338 |
+
|
339 |
+
/**
|
340 |
+
* TODO: dodoc.
|
341 |
+
* @since 3.4.2
|
342 |
+
*/
|
343 |
+
function wpbdp_text_from_template( $setting_name, $replacements = array() ) {
|
344 |
+
global $wpbdp;
|
345 |
+
|
346 |
+
$setting = $wpbdp->settings->get_setting( $setting_name );
|
347 |
+
|
348 |
+
if ( ! $setting )
|
349 |
+
return false;
|
350 |
+
|
351 |
+
$text = wpbdp_get_option( $setting_name );
|
352 |
+
|
353 |
+
if ( ! $text )
|
354 |
+
return false;
|
355 |
+
|
356 |
+
$placeholders = isset( $setting->args['placeholders'] ) ? array_keys( $setting->args['placeholders'] ) : array();
|
357 |
+
|
358 |
+
foreach ( $replacements as $pholder => $repl ) {
|
359 |
+
if ( ! in_array( $pholder, $placeholders, true ) )
|
360 |
+
continue;
|
361 |
+
|
362 |
+
$text = str_replace( '[' . $pholder . ']', $repl, $text );
|
363 |
+
}
|
364 |
+
|
365 |
+
return $text;
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* @since 3.5.4
|
370 |
+
*/
|
371 |
+
function wpbdp_email_from_template( $setting, $replacements = array(), $args = array() ) {
|
372 |
+
global $wpbdp;
|
373 |
+
|
374 |
+
$setting = $wpbdp->settings->get_setting( $setting );
|
375 |
+
|
376 |
+
if ( ! $setting || 'email_template' != $setting->type )
|
377 |
+
return false;
|
378 |
+
|
379 |
+
if ( ! class_exists( 'WPBDP_Email' ) )
|
380 |
+
require_once( WPBDP_PATH . 'core/class-email.php' );
|
381 |
+
|
382 |
+
$placeholders = isset( $setting->args['placeholders'] ) && is_array( $setting->args['placeholders'] ) ? $setting->args['placeholders'] : array();
|
383 |
+
$value = wpbdp_get_option( $setting->name );
|
384 |
+
|
385 |
+
// Add core replacements.
|
386 |
+
$replacements = array_merge( $replacements, array(
|
387 |
+
'site-title' => get_bloginfo( 'name' ),
|
388 |
+
'site-link' => sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'name' ) ),
|
389 |
+
'site-url' => sprintf( '<a href="%s">%s</a>', get_bloginfo( 'url' ), get_bloginfo( 'url' ) ),
|
390 |
+
'directory-url' => sprintf( '<a href="%1$s">%1$s</a>', wpbdp_get_page_link( 'main' ) ),
|
391 |
+
'today' => date_i18n( get_option( 'date_format' ) ),
|
392 |
+
'now' => date_i18n( get_option( 'time_format' ) )
|
393 |
+
) );
|
394 |
+
|
395 |
+
// Support old-style settings.
|
396 |
+
if ( ! is_array( $value ) ) {
|
397 |
+
$subject = $setting->default['subject'];
|
398 |
+
$body = $setting->default['body'];
|
399 |
+
} else {
|
400 |
+
$subject = $value['subject'];
|
401 |
+
$body = $value['body'];
|
402 |
+
}
|
403 |
+
|
404 |
+
$email = new WPBDP_Email();
|
405 |
+
$email->subject = $subject;
|
406 |
+
$email->body = $body;
|
407 |
+
|
408 |
+
foreach ( array_keys( $placeholders ) as $placeholder ) {
|
409 |
+
if ( ! isset( $replacements[ $placeholder ] ) )
|
410 |
+
continue;
|
411 |
+
|
412 |
+
$email->subject = str_replace( '[' . $placeholder . ']', $replacements[ $placeholder ], $email->subject );
|
413 |
+
$email->body = str_replace( '[' . $placeholder . ']', $replacements[ $placeholder ], $email->body );
|
414 |
+
}
|
415 |
+
|
416 |
+
return $email;
|
417 |
+
}
|
418 |
+
|
419 |
+
function wpbdp_admin_pointer( $selector, $title, $content_ = '',
|
420 |
+
$primary_button = false, $primary_action = '',
|
421 |
+
$secondary_button = false, $secondary_action = '',
|
422 |
+
$options = array() ) {
|
423 |
+
if ( ! current_user_can( 'administrator' ) || ( get_bloginfo( 'version' ) < '3.3' ) )
|
424 |
+
return;
|
425 |
+
|
426 |
+
$content = '';
|
427 |
+
$content .= '<h3>' . $title . '</h3>';
|
428 |
+
$content .= '<p>' . $content_ . '</p>';
|
429 |
+
?>
|
430 |
+
<script type="text/javascript">
|
431 |
+
//<![CDATA[
|
432 |
+
jQuery(function( $ ) {
|
433 |
+
var wpbdp_pointer = $( '<?php echo $selector; ?>' ).pointer({
|
434 |
+
'content': <?php echo json_encode( $content ); ?>,
|
435 |
+
'position': { 'edge': '<?php echo isset( $options['edge'] ) ? $options['edge'] : 'top'; ?>',
|
436 |
+
'align': '<?php echo isset( $options['align'] ) ? $options['align'] : 'center'; ?>' },
|
437 |
+
'buttons': function( e, t ) {
|
438 |
+
<?php if ( ! $secondary_button ): ?>
|
439 |
+
var b = $( '<a id="wpbdp-pointer-b1" class="button-primary">' + '<?php echo $primary_button; ?>' + '</a>' );
|
440 |
+
<?php else: ?>
|
441 |
+
var b = $( '<a id="wpbdp-pointer-b2" class="button-secondary" style="margin-right: 15px;">' + '<?php echo $secondary_button; ?>' + '</a>' );
|
442 |
+
<?php endif; ?>
|
443 |
+
return b;
|
444 |
+
}
|
445 |
+
}).pointer('open');
|
446 |
+
|
447 |
+
<?php if ( $secondary_button ): ?>
|
448 |
+
$( '#wpbdp-pointer-b2' ).before( '<a id="wpbdp-pointer-b1" class="button-primary">' + '<?php echo $primary_button; ?>' + '</a>' );
|
449 |
+
$( '#wpbdp-pointer-b2' ).click(function(e) {
|
450 |
+
e.preventDefault();
|
451 |
+
<?php if ( $secondary_action ): ?>
|
452 |
+
<?php echo $secondary_action; ?>
|
453 |
+
<?php endif; ?>
|
454 |
+
wpbdp_pointer.pointer( 'close' );
|
455 |
+
});
|
456 |
+
<?php endif; ?>
|
457 |
+
|
458 |
+
$( '#wpbdp-pointer-b1' ).click(function(e) {
|
459 |
+
e.preventDefault();
|
460 |
+
<?php if ( $primary_action ): ?>
|
461 |
+
<?php echo $primary_action; ?>
|
462 |
+
<?php endif; ?>
|
463 |
+
wpbdp_pointer.pointer( 'close' );
|
464 |
+
});
|
465 |
+
|
466 |
+
});
|
467 |
+
//]]>
|
468 |
+
</script>
|
469 |
+
<?php
|
470 |
+
}
|
471 |
+
|
472 |
+
/**
|
473 |
+
* No op object used to prevent modules from breaking a site while performing a manual upgrade
|
474 |
+
* or something similar.
|
475 |
+
* Instances of this class allow accessing any property or calling any function without side effects (errors).
|
476 |
+
*
|
477 |
+
* @since 3.4dev
|
478 |
+
*/
|
479 |
+
class WPBDP_NoopObject {
|
480 |
+
|
481 |
+
public function __construct() {
|
482 |
+
}
|
483 |
+
|
484 |
+
public function __set( $k, $v ) { }
|
485 |
+
public function __get( $k ) { return null; }
|
486 |
+
public function __isset( $k ) { return false; }
|
487 |
+
public function __unset( $k ) { }
|
488 |
+
|
489 |
+
public function __call( $name, $args = array() ) {
|
490 |
+
return false;
|
491 |
+
}
|
492 |
+
|
493 |
+
}
|
494 |
+
|
495 |
+
|
core/view-checkout.php
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
class WPBDP_Checkout_Page extends WPBDP_View {
|
5 |
+
|
6 |
+
private $api = null;
|
7 |
+
private $payment = null;
|
8 |
+
private $errors = array();
|
9 |
+
|
10 |
+
public function __construct( &$payment = null ) {
|
11 |
+
$this->api = wpbdp_payments_api();
|
12 |
+
$this->payment = $payment;
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get_page_name() {
|
16 |
+
return 'checkout';
|
17 |
+
}
|
18 |
+
|
19 |
+
public function dispatch() {
|
20 |
+
if ( ! $this->payment ) {
|
21 |
+
$q = isset( $_REQUEST['payment'] ) ? $_REQUEST['payment'] : null;
|
22 |
+
|
23 |
+
if ( $q ) {
|
24 |
+
$q = urldecode( base64_decode( $q ) );
|
25 |
+
parse_str( $q, $payment_data );
|
26 |
+
|
27 |
+
if ( isset( $payment_data['payment_id'] ) && isset( $payment_data['verify'] ) ) { // TODO: check 'verify'.
|
28 |
+
$this->payment = WPBDP_Payment::get( $payment_data['payment_id'] );
|
29 |
+
}
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
if ( ! $this->payment )
|
34 |
+
return wpbdp_render_msg( _x( 'Invalid payment id.', 'payments', 'WPBDM' ), 'error' );
|
35 |
+
|
36 |
+
$step = 'gateway_selection';
|
37 |
+
|
38 |
+
if ( $this->payment->is_rejected() || $this->payment->is_canceled() )
|
39 |
+
$step = 'rejected';
|
40 |
+
elseif ( ! $this->payment->is_pending() ) {
|
41 |
+
$step = 'done';
|
42 |
+
} else {
|
43 |
+
if ( $this->payment->get_data( 'returned' ) )
|
44 |
+
$step = 'pending_verification';
|
45 |
+
elseif ( $this->payment->get_gateway() )
|
46 |
+
$step = 'checkout';
|
47 |
+
}
|
48 |
+
|
49 |
+
return call_user_func( array( &$this, $step ) );
|
50 |
+
}
|
51 |
+
|
52 |
+
private function gateway_selection() {
|
53 |
+
global $wpbdp;
|
54 |
+
|
55 |
+
// Auto-select gateway if there is only one available.
|
56 |
+
$gateways = $wpbdp->payments->get_available_methods();
|
57 |
+
if ( 1 == count( $gateways ) ) {
|
58 |
+
$this->payment->set_payment_method( array_pop( $gateways ) );
|
59 |
+
$this->payment->save();
|
60 |
+
return $this->checkout();
|
61 |
+
}
|
62 |
+
|
63 |
+
$html = '';
|
64 |
+
do_action_ref_array( 'wpbdp_checkout_page_process', array( &$this->payment ) );
|
65 |
+
|
66 |
+
if ( isset( $_POST['payment_method'] ) ) {
|
67 |
+
$payment_method = trim( $_POST['payment_method'] );
|
68 |
+
|
69 |
+
if ( ! $payment_method ) {
|
70 |
+
// $html .= wpbdp_render_msg( _x( 'Please select a valid payment method.', 'checkout', 'WPBDM' ), 'error' );
|
71 |
+
} else {
|
72 |
+
$this->payment->set_payment_method( $payment_method );
|
73 |
+
$this->payment->save();
|
74 |
+
return $this->checkout();
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
$html .= '<form action="' . esc_url( $this->payment->get_checkout_url() ) . '" method="POST">';
|
79 |
+
$html .= $wpbdp->payments->render_invoice( $this->payment );
|
80 |
+
$html .= wpbdp_capture_action_array( 'wpbdp_checkout_page_before_method_selection', array( &$this->payment ) );
|
81 |
+
$html .= $wpbdp->payments->render_payment_method_selection( $this->payment );
|
82 |
+
$html .= '<input type="submit" value="' . _x( 'Continue', 'checkout', 'WPBDM' ) . '" />';
|
83 |
+
$html .= '</form>';
|
84 |
+
|
85 |
+
return $html;
|
86 |
+
}
|
87 |
+
|
88 |
+
private function checkout() {
|
89 |
+
if ( ! is_ssl() && wpbdp_get_option( 'payments-use-https' ) ) {
|
90 |
+
return wpbdp_render_msg(
|
91 |
+
str_replace( '<a>',
|
92 |
+
'<a href="' . $this->payment->get_checkout_url() . '">',
|
93 |
+
_x( 'Payments are not allowed on the non-secure version of this site. Please <a>continue to the secure server to proceed with your payment</a>.', 'checkout', 'WPBDM' ) ),
|
94 |
+
'error'
|
95 |
+
);
|
96 |
+
}
|
97 |
+
|
98 |
+
$html = '';
|
99 |
+
$html .= $this->api->render_standard_checkout_page( $this->payment, array( 'retry_rejected' => true ) );
|
100 |
+
|
101 |
+
return $html;
|
102 |
+
}
|
103 |
+
|
104 |
+
private function pending_verification() {
|
105 |
+
$message = wpbdp_get_option( 'payment-message' );
|
106 |
+
|
107 |
+
if ( ! $message )
|
108 |
+
$message .= wpbdp_render_msg( _x( 'Your payment is being verified. This usually takes a few minutes but can take up to 24 hours.', 'checkout', 'WPBDM' ) );
|
109 |
+
|
110 |
+
$html = '';
|
111 |
+
$html .= $message;
|
112 |
+
$html .= $this->api->render_details( $this->payment );
|
113 |
+
$html .= '<p>';
|
114 |
+
$html .= sprintf( '<a href="%s">%s</a>',
|
115 |
+
wpbdp_get_page_link( 'main' ),
|
116 |
+
_x( '← Return to Directory.', 'checkout', 'WPBDM' ) );
|
117 |
+
$html .= '</p>';
|
118 |
+
|
119 |
+
return $html;
|
120 |
+
}
|
121 |
+
|
122 |
+
private function done() {
|
123 |
+
$listing = WPBDP_Listing::get( $this->payment->get_listing_id() );
|
124 |
+
|
125 |
+
$html = '';
|
126 |
+
$html .= wpbdp_render_msg( _x( 'Your payment was received sucessfully.', 'checkout', 'WPBDM' ) );
|
127 |
+
$html .= $this->api->render_details( $this->payment );
|
128 |
+
|
129 |
+
$html .= '<p>';
|
130 |
+
if ( $listing->is_published() )
|
131 |
+
$html .= sprintf( '<a href="%s">%s</a>',
|
132 |
+
$listing->get_permalink(),
|
133 |
+
_x( '← Return to your listing.', 'checkout', 'WPBDM' ) );
|
134 |
+
else
|
135 |
+
$html .= sprintf( '<a href="%s">%s</a>',
|
136 |
+
wpbdp_get_page_link( 'main' ),
|
137 |
+
_x( '← Return to Directory.', 'checkout', 'WPBDM' ) );
|
138 |
+
$html .= '</p>';
|
139 |
+
|
140 |
+
return $html;
|
141 |
+
}
|
142 |
+
|
143 |
+
private function rejected() {
|
144 |
+
$html = '';
|
145 |
+
$html .= wpbdp_render_msg( implode( '<br />', $this->payment->get_data('errors') ), 'error' );
|
146 |
+
$html .= $this->api->render_details( $this->payment );
|
147 |
+
|
148 |
+
return $html;
|
149 |
+
}
|
150 |
+
|
151 |
+
}
|
core/view-delete-listing.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
class WPBDP_Delete_Listing_View extends WPBDP_View {
|
5 |
+
|
6 |
+
function dispatch() {
|
7 |
+
$listing_id = intval( $_REQUEST['listing_id'] );
|
8 |
+
|
9 |
+
if ( ! wpbdp_user_can( 'delete', $listing_id ) ) {
|
10 |
+
$html .= wpbdp_render_msg( _x( 'Please log in to delete the listing.', 'delete listing', 'WPBDM' ) );
|
11 |
+
$html .= wpbdp_render( 'parts/login-required', array( 'show_message' => false ) );
|
12 |
+
return $html;
|
13 |
+
}
|
14 |
+
|
15 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
16 |
+
$nonce = isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : '';
|
17 |
+
|
18 |
+
if ( ! $listing )
|
19 |
+
die();
|
20 |
+
|
21 |
+
if ( $nonce && wp_verify_nonce( $nonce, 'delete listing ' . $listing->get_id() ) ) {
|
22 |
+
$listing->delete();
|
23 |
+
return wpbdp_render_msg( _x( 'Your listing has been deleted.', 'delete listing', 'WPBDM' ) );
|
24 |
+
}
|
25 |
+
|
26 |
+
return wpbdp_render( 'delete-listing-confirm', array( 'listing' => $listing,
|
27 |
+
'has_recurring' => $this->has_recurring_fee( $listing ) ) );
|
28 |
+
}
|
29 |
+
|
30 |
+
private function has_recurring_fee( &$listing ) {
|
31 |
+
global $wpdb;
|
32 |
+
|
33 |
+
return (bool) $wpdb->get_var( $wpdb->prepare(
|
34 |
+
"SELECT 1 AS x FROM {$wpdb->prefix}wpbdp_listing_fees WHERE listing_id = %d AND recurring = %d",
|
35 |
+
$listing->get_id(),
|
36 |
+
1 ) );
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
core/view-listing-contact.php
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Listing contact page.
|
6 |
+
* @since 3.4
|
7 |
+
*/
|
8 |
+
class WPBDP_Listing_Contact_View extends WPBDP_View {
|
9 |
+
|
10 |
+
private $errors = array();
|
11 |
+
|
12 |
+
private $name = '';
|
13 |
+
private $email = '';
|
14 |
+
private $message = '';
|
15 |
+
|
16 |
+
|
17 |
+
public function __construct() {
|
18 |
+
}
|
19 |
+
|
20 |
+
public function get_page_name() {
|
21 |
+
return 'sendcontactmessage';
|
22 |
+
}
|
23 |
+
|
24 |
+
private function prepare_input() {
|
25 |
+
if ( $_POST )
|
26 |
+
$_POST = stripslashes_deep( $_POST );
|
27 |
+
|
28 |
+
$current_user = is_user_logged_in() ? wp_get_current_user() : null;
|
29 |
+
|
30 |
+
$this->name = $current_user ? $current_user->data->user_login : ( isset( $_POST['commentauthorname'] ) ? trim( $_POST['commentauthorname'] ) : '' );
|
31 |
+
$this->email = $current_user ? $current_user->data->user_email : ( isset( $_POST['commentauthoremail'] ) ? trim( $_POST['commentauthoremail'] ) : '' );
|
32 |
+
$this->message = isset( $_POST['commentauthormessage'] ) ? trim( wp_kses( $_POST['commentauthormessage'], array() ) ) : '';
|
33 |
+
|
34 |
+
}
|
35 |
+
|
36 |
+
private function validate() {
|
37 |
+
$this->errors = array();
|
38 |
+
|
39 |
+
if ( ! isset( $_REQUEST['listing_id'] ) )
|
40 |
+
die();
|
41 |
+
|
42 |
+
// Verify nonce.
|
43 |
+
if ( ! isset( $_POST['_wpnonce'] )
|
44 |
+
|| ! isset( $_POST['_wp_http_referer'] )
|
45 |
+
|| ! wp_verify_nonce( $_POST['_wpnonce'], 'contact-form-' . $_REQUEST['listing_id'] ) )
|
46 |
+
die();
|
47 |
+
|
48 |
+
if ( ! $this->name )
|
49 |
+
$this->errors[] = _x( 'Please enter your name.', 'contact-message', 'WPBDM' );
|
50 |
+
|
51 |
+
if ( ! wpbdp_validate_value( $this->email, 'email' ) )
|
52 |
+
$this->errors[] = _x( "Please enter a valid email.", 'contact-message', "WPBDM" );
|
53 |
+
|
54 |
+
if ( ! $this->message )
|
55 |
+
$this->errors[] = _x( 'You did not enter a message.', 'contact-message', 'WPBDM' );
|
56 |
+
|
57 |
+
if ( wpbdp_get_option( 'recaptcha-on' ) && ! wpbdp_recaptcha_check_answer() )
|
58 |
+
$this->errors[] = _x( "The reCAPTCHA wasn't entered correctly.", 'contact-message', 'WPBDM' );
|
59 |
+
|
60 |
+
return empty( $this->errors );
|
61 |
+
}
|
62 |
+
|
63 |
+
private function can_submit( $listing_id = 0, &$error_msg = '' ) {
|
64 |
+
if ( wpbdp_get_option( 'contact-form-require-login' ) && ! is_user_logged_in() ) {
|
65 |
+
$error_msg = str_replace( '<a>',
|
66 |
+
'<a href="' . wp_login_url( site_url( $_SERVER['REQUEST_URI'] ) ) . '">',
|
67 |
+
_x( 'Please <a>log in</a> to be able to send messages to the listing owner.', 'contact form', 'WPBDM' ) );
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
|
71 |
+
$daily_limit = max( 0, intval( wpbdp_get_option( 'contact-form-daily-limit' ) ) );
|
72 |
+
|
73 |
+
if ( ! $daily_limit )
|
74 |
+
return true;
|
75 |
+
|
76 |
+
$today = date( 'Ymd', current_time( 'timestamp' ) );
|
77 |
+
$data = get_post_meta( $listing_id, '_wpbdp_contact_limit', true );
|
78 |
+
|
79 |
+
if ( ! $data || ! is_array( $data ) )
|
80 |
+
$data = array( 'last_date' => $today, 'count' => 0 );
|
81 |
+
|
82 |
+
if ( $today != $data['last_date'] )
|
83 |
+
$data['count'] = 0;
|
84 |
+
|
85 |
+
if ( $data['count'] >= $daily_limit ) {
|
86 |
+
$error_msg = _x( 'This contact form is temporarily disabled. Please try again later.', 'contact form', 'WPBDM' );
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
|
90 |
+
return true;
|
91 |
+
}
|
92 |
+
|
93 |
+
private function update_contacts( $listing_id ) {
|
94 |
+
$daily_limit = max( 0, intval( wpbdp_get_option( 'contact-form-daily-limit' ) ) );
|
95 |
+
|
96 |
+
if ( ! $daily_limit )
|
97 |
+
return;
|
98 |
+
|
99 |
+
$today = date( 'Ymd', current_time( 'timestamp' ) );
|
100 |
+
$data = get_post_meta( $listing_id, '_wpbdp_contact_limit', true );
|
101 |
+
|
102 |
+
if ( ! $data || ! is_array( $data ) )
|
103 |
+
$data = array( 'last_date' => $today, 'count' => 0 );
|
104 |
+
|
105 |
+
if ( $today != $data['last_date'] )
|
106 |
+
$data['count'] = 0;
|
107 |
+
|
108 |
+
$data['count'] = $data['count'] + 1;
|
109 |
+
update_post_meta( $listing_id, '_wpbdp_contact_limit', $data );
|
110 |
+
}
|
111 |
+
|
112 |
+
public function render_form( $listing_id = 0, $validation_errors = array() ) {
|
113 |
+
if ( ! $listing_id || ! apply_filters('wpbdp_show_contact_form', wpbdp_get_option( 'show-contact-form' ), $listing_id ) )
|
114 |
+
return '';
|
115 |
+
|
116 |
+
$html = '';
|
117 |
+
$html .= '<div class="contact-form">';
|
118 |
+
$html .= '<h3>' . _x('Send Message to listing owner', 'templates', 'WPBDM') . '</h3>';
|
119 |
+
|
120 |
+
$form = '';
|
121 |
+
|
122 |
+
if ( ! $this->can_submit( $listing_id, $error_msg ) ) {
|
123 |
+
$form = wpbdp_render_msg( $error_msg );
|
124 |
+
} else {
|
125 |
+
$form = wpbdp_render( 'listing-contactform', array(
|
126 |
+
'validation_errors' => $validation_errors,
|
127 |
+
'listing_id' => $listing_id,
|
128 |
+
'current_user' => is_user_logged_in() ? wp_get_current_user() : null,
|
129 |
+
'recaptcha' => wpbdp_get_option( 'recaptcha-on' ) ? wpbdp_recaptcha() : '',
|
130 |
+
false ) );
|
131 |
+
}
|
132 |
+
|
133 |
+
$html .= $form;
|
134 |
+
$html .= '</div>';
|
135 |
+
|
136 |
+
return $html;
|
137 |
+
}
|
138 |
+
|
139 |
+
public function dispatch() {
|
140 |
+
$listing_id = intval( isset( $_REQUEST['listing_id'] ) ? $_REQUEST['listing_id'] : 0 );
|
141 |
+
|
142 |
+
if ( ! $listing_id )
|
143 |
+
return '';
|
144 |
+
|
145 |
+
if ( ! $this->can_submit( $listing_id, $error_msg ) )
|
146 |
+
return wpbdp_render_msg( $error_msg, 'error' );
|
147 |
+
|
148 |
+
$this->listing_id = $listing_id;
|
149 |
+
$this->prepare_input();
|
150 |
+
|
151 |
+
if ( ! $this->validate() )
|
152 |
+
return $this->render_form( $listing_id, $this->errors );
|
153 |
+
|
154 |
+
// Compose e-mail message.
|
155 |
+
$replacements = array( 'listing-url' => get_permalink( $listing_id ),
|
156 |
+
'listing' => get_the_title( $listing_id ),
|
157 |
+
'name' => $this->name,
|
158 |
+
'email' => $this->email,
|
159 |
+
'message' => $this->message,
|
160 |
+
'date' => date_i18n( __('l F j, Y \a\t g:i a'), current_time( 'timestamp' ) ) );
|
161 |
+
$email = wpbdp_email_from_template( 'email-templates-contact',
|
162 |
+
$replacements );
|
163 |
+
$email->from = "{$this->name} <{$this->email}>";
|
164 |
+
$email->to = wpbusdirman_get_the_business_email( $listing_id );
|
165 |
+
$email->reply_to = $this->email;
|
166 |
+
|
167 |
+
if ( in_array( 'listing-contact', wpbdp_get_option( 'admin-notifications' ), true ) ) {
|
168 |
+
$email->cc[] = get_bloginfo( 'admin_email' );
|
169 |
+
|
170 |
+
if ( wpbdp_get_option( 'admin-notifications-cc' ) )
|
171 |
+
$email->cc[] = wpbdp_get_option( 'admin-notifications-cc' );
|
172 |
+
}
|
173 |
+
|
174 |
+
$html = '';
|
175 |
+
|
176 |
+
if( $email->send() ) {
|
177 |
+
$html .= wpbdp_render_msg( 'Your message has been sent.', 'contact-message', 'WPBDM' );
|
178 |
+
$this->update_contacts( $listing_id );
|
179 |
+
} else {
|
180 |
+
$html .= wpbdp_render_msg( _x("There was a problem encountered. Your message has not been sent", 'contact-message', "WPBDM"), 'error' );
|
181 |
+
}
|
182 |
+
|
183 |
+
$html .= sprintf('<p><a href="%s">%s</a></p>', get_permalink($listing_id), _x('Return to listing.', 'contact-message', "WPBDM"));
|
184 |
+
return $html;
|
185 |
+
}
|
186 |
+
|
187 |
+
}
|
188 |
+
|
core/view-manage-recurring.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* @since 3.5.3
|
6 |
+
*/
|
7 |
+
class WPBDP_Manage_Subscriptions_View extends WPBDP_View {
|
8 |
+
|
9 |
+
private $subscriptions = array();
|
10 |
+
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
}
|
14 |
+
|
15 |
+
public function dispatch() {
|
16 |
+
if ( ! is_user_logged_in() ) {
|
17 |
+
return wpbdp_render( 'parts/login-required', array(), false );
|
18 |
+
}
|
19 |
+
|
20 |
+
$this->subscriptions = $this->get_subscription_info();
|
21 |
+
|
22 |
+
if ( ! $this->subscriptions )
|
23 |
+
return wpbdp_render_msg( _x( 'You are not on recurring payments for any of your listings.', 'manage subscriptions', 'WPBDM' ) );
|
24 |
+
|
25 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'subscription' ) );
|
26 |
+
|
27 |
+
if ( isset( $_GET['cancel'] ) && $_GET['cancel'] )
|
28 |
+
return $this->cancel_subscription();
|
29 |
+
else
|
30 |
+
return $this->subscription_list();
|
31 |
+
}
|
32 |
+
|
33 |
+
private function get_subscription_info() {
|
34 |
+
global $wpdb;
|
35 |
+
$listings = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d",
|
36 |
+
get_current_user_id() ) );
|
37 |
+
$info = array();
|
38 |
+
|
39 |
+
foreach ( $listings as $listing_id ) {
|
40 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
41 |
+
$categories = $listing->get_categories( 'all' );
|
42 |
+
|
43 |
+
foreach ( $categories as $cat ) {
|
44 |
+
if ( ! $cat->recurring )
|
45 |
+
continue;
|
46 |
+
|
47 |
+
if ( ! isset( $info[ $listing_id ] ) )
|
48 |
+
$info[ $listing_id ] = array( 'listing' => $listing, 'subscriptions' => array() );
|
49 |
+
|
50 |
+
$info[ $listing_id ]['subscriptions'][] = $cat;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
return $info;
|
55 |
+
}
|
56 |
+
|
57 |
+
private function subscription_list() {
|
58 |
+
return wpbdp_render( 'manage-recurring', array( 'subscriptions' => $this->subscriptions ), false );
|
59 |
+
}
|
60 |
+
|
61 |
+
private function decode_subscription_hash( $hash = '' ) {
|
62 |
+
$hash = urldecode( trim( $hash ) );
|
63 |
+
|
64 |
+
if ( ! $hash )
|
65 |
+
return false;
|
66 |
+
|
67 |
+
parse_str( base64_decode( $hash ), $hash_data );
|
68 |
+
|
69 |
+
if ( ! $hash_data || ! isset( $hash_data['listing_id'] ) || ! isset( $hash_data['category_id'] ) )
|
70 |
+
return false;
|
71 |
+
|
72 |
+
$listing = WPBDP_Listing::get( intval( $hash_data['listing_id'] ) );
|
73 |
+
$category_id = intval( $hash_data['category_id'] );
|
74 |
+
|
75 |
+
if ( ! $listing || ! $category_id || $listing->get_author_meta( 'ID' ) != get_current_user_id() )
|
76 |
+
return false;
|
77 |
+
|
78 |
+
$category_info = $listing->get_category_info( $category_id );
|
79 |
+
|
80 |
+
if ( ! $category_info || ! $category_info->recurring )
|
81 |
+
return false;
|
82 |
+
|
83 |
+
return compact( 'listing', 'category_info' );
|
84 |
+
}
|
85 |
+
|
86 |
+
private function cancel_subscription() {
|
87 |
+
$data = $this->decode_subscription_hash( isset( $_GET['cancel'] ) ? $_GET['cancel'] : '' );
|
88 |
+
|
89 |
+
if ( ! $data )
|
90 |
+
return wpbdp_render_msg( _x( 'Invalid subscription.', 'manage subscriptions', 'WPBDM' ), 'error' );
|
91 |
+
|
92 |
+
global $wpbdp;
|
93 |
+
$unsubscribe_form = $wpbdp->payments->render_unsubscribe_integration( $data['category_info'],
|
94 |
+
$data['listing'] );
|
95 |
+
|
96 |
+
return wpbdp_render( 'manage-recurring-cancel', array( 'listing' => $data['listing'],
|
97 |
+
'subscription' => $data['category_info'],
|
98 |
+
'unsubscribe_form' => $unsubscribe_form ) );
|
99 |
+
}
|
100 |
+
|
101 |
+
}
|
core/view-renew-listing.php
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Renew listing view.
|
6 |
+
*/
|
7 |
+
class WPBDP_Renew_Listing_Page extends WPBDP_View {
|
8 |
+
|
9 |
+
private $category = null;
|
10 |
+
private $listing = null;
|
11 |
+
|
12 |
+
public function get_page_name() {
|
13 |
+
return 'renewlisting';
|
14 |
+
}
|
15 |
+
|
16 |
+
public function dispatch() {
|
17 |
+
if ( ! wpbdp_get_option( 'listing-renewal' ) )
|
18 |
+
return wpbdp_render_msg( _x( 'Listing renewal is disabled at this moment. Please try again later.', 'renewal', 'WPBDM' ), 'error' );
|
19 |
+
|
20 |
+
if ( ! $this->obtain_renewal_info() )
|
21 |
+
return wpbdp_render_msg( _x( 'Your renewal ID is invalid. Please use the URL you were given on the renewal e-mail message.', 'renewal', 'WPBDM' ), 'error' );
|
22 |
+
|
23 |
+
if ( ! wpbdp_user_can( 'edit', $this->listing->get_id() ) ) {
|
24 |
+
$html = '';
|
25 |
+
// $html .= wpbdp_render_msg( _x( 'You don\'t have permission to access this page. Please login.', 'renewal', 'WPBDM' ), 'error' );
|
26 |
+
$html .= wpbdp_render( 'parts/login-required', array(), false );
|
27 |
+
return $html;
|
28 |
+
}
|
29 |
+
|
30 |
+
if ( $this->category->recurring )
|
31 |
+
return $this->recurring_management();
|
32 |
+
|
33 |
+
if ( $this->category->payment_id )
|
34 |
+
return $this->checkout();
|
35 |
+
|
36 |
+
return $this->fee_selection();
|
37 |
+
}
|
38 |
+
|
39 |
+
private function fee_selection() {
|
40 |
+
// Cancel renewal?
|
41 |
+
if ( isset( $_POST['cancel-renewal'] ) ) {
|
42 |
+
$this->listing->remove_category( $this->category->id, true );
|
43 |
+
|
44 |
+
if ( ! $this->listing->get_categories( 'all' ) )
|
45 |
+
$this->listing->delete();
|
46 |
+
|
47 |
+
return wpbdp_render_msg( _x( 'Your renewal was successfully cancelled.', 'renewal', 'WPBDM' ) );
|
48 |
+
}
|
49 |
+
|
50 |
+
$fees = wpbdp_get_fees_for_category( $this->category->id );
|
51 |
+
|
52 |
+
if ( isset( $_POST['fees'] ) && isset( $_POST['fees'][ $this->category->id ] ) ) {
|
53 |
+
$fee_id = intval( $_POST['fees'][ $this->category->id ] );
|
54 |
+
|
55 |
+
if ( $fee = wpbdp_get_fee( $fee_id ) ) {
|
56 |
+
$payment = new WPBDP_Payment( array( 'listing_id' => $this->listing->get_id() ) );
|
57 |
+
$payment->add_item( 'fee',
|
58 |
+
$fee->amount,
|
59 |
+
sprintf( _x( 'Fee "%s" renewal for category "%s"', 'listings', 'WPBDM' ),
|
60 |
+
$fee->label,
|
61 |
+
wpbdp_get_term_name( $this->category->id ) ),
|
62 |
+
array( 'fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images ),
|
63 |
+
$this->category->id,
|
64 |
+
$fee_id );
|
65 |
+
$payment->save();
|
66 |
+
return $this->dispatch();
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
return wpbdp_render( 'renew-listing', array( 'listing' => $this->listing, 'category' => $this->category, 'fees' => $fees ) );
|
71 |
+
}
|
72 |
+
|
73 |
+
private function checkout() {
|
74 |
+
$payment = WPBDP_Payment::get( $this->category->payment_id );
|
75 |
+
|
76 |
+
if ( ! $payment )
|
77 |
+
return wpbdp_render_msg( _x( 'Invalid renewal state.', 'renewal', 'WPBDM' ), 'error' );
|
78 |
+
|
79 |
+
require_once( WPBDP_PATH . 'core/view-checkout.php' );
|
80 |
+
$checkout = new WPBDP_Checkout_Page( $payment );
|
81 |
+
return $checkout->dispatch();
|
82 |
+
}
|
83 |
+
|
84 |
+
private function recurring_management() {
|
85 |
+
global $wpbdp;
|
86 |
+
|
87 |
+
$html = '';
|
88 |
+
$html .= '<div id="wpbdp-renewal-page" class="wpbdp-renewal-page businessdirectory-renewal businessdirectory wpbdp-page">';
|
89 |
+
$html .= '<h2>' . _x('Recurring Fee Management', 'templates', 'WPBDM') . '</h2>';
|
90 |
+
$html .= '<p>' . _x( 'Because you are on a recurring fee plan you don\'t have to renew your listing right now as this will be handled automatically when renewal comes.', 'renew', 'WPBDM' ) . '</p>';
|
91 |
+
|
92 |
+
$html .= '<h4>' . _x( 'Current Fee Details', 'renewal', 'WPBDM' ) . '</h4>';
|
93 |
+
$html .= '<dl class="recurring-fee-details">';
|
94 |
+
$html .= '<dt>' . _x( 'Number of images:', 'renewal', 'WPBDM' ) . '</dt>';
|
95 |
+
$html .= '<dd>' . $this->category->fee_images . '</dd>';
|
96 |
+
$html .= '<dt>' . _x( 'Expiration date:', 'renewal', 'WPBDM' ) . '</dt>';
|
97 |
+
$html .= '<dd>' . date_i18n( get_option( 'date_format' ), strtotime( $this->category->expires_on ) ) . '</dd>';
|
98 |
+
$html .= '</dl>';
|
99 |
+
|
100 |
+
$html .= '<p>' . _x( 'However, if you want to cancel your subscription you can do that on this page. When the renewal time comes you\'ll be able to change your settings again.', 'renew', 'WPBDM' ) . '</p>';
|
101 |
+
$html .= $wpbdp->payments->render_unsubscribe_integration( $this->category, $this->listing );
|
102 |
+
|
103 |
+
$html .= '</div>';
|
104 |
+
|
105 |
+
return $html;
|
106 |
+
}
|
107 |
+
|
108 |
+
private function obtain_renewal_info() {
|
109 |
+
$renewal_id = urldecode( trim( $_GET['renewal_id'] ) );
|
110 |
+
|
111 |
+
if ( ! $renewal_id )
|
112 |
+
return false;
|
113 |
+
|
114 |
+
parse_str( base64_decode( $renewal_id ), $renewal_data );
|
115 |
+
|
116 |
+
if ( ! $renewal_data || ! isset( $renewal_data['listing_id'] ) || ! isset( $renewal_data['category_id'] ) )
|
117 |
+
return false;
|
118 |
+
|
119 |
+
$listing = WPBDP_Listing::get( intval( $renewal_data['listing_id'] ) );
|
120 |
+
$category_id = intval( $renewal_data['category_id'] );
|
121 |
+
|
122 |
+
if ( ! $listing )
|
123 |
+
return false;
|
124 |
+
|
125 |
+
$category_info = $listing->get_category_info( $category_id );
|
126 |
+
|
127 |
+
if ( ! $category_info )
|
128 |
+
return false;
|
129 |
+
|
130 |
+
$this->category = $category_info;
|
131 |
+
$this->listing = $listing;
|
132 |
+
|
133 |
+
return true;
|
134 |
+
}
|
135 |
+
|
136 |
+
}
|
core/view-submit-listing.php
ADDED
@@ -0,0 +1,576 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Submit/edit listing process page.
|
6 |
+
* @since 3.3
|
7 |
+
*/
|
8 |
+
class WPBDP_Submit_Listing_Page extends WPBDP_View {
|
9 |
+
|
10 |
+
private $state = null;
|
11 |
+
private $messages = array();
|
12 |
+
private $errors = array();
|
13 |
+
|
14 |
+
public function __construct( $listing_id = 0, $preview = false ) {
|
15 |
+
$this->state = isset( $_REQUEST['_state'] ) && $_REQUEST['_state'] ? WPBDP_Listing_Submit_State::get( $_REQUEST['_state'] ) : new WPBDP_Listing_Submit_State( $listing_id );
|
16 |
+
|
17 |
+
if ( ! $preview )
|
18 |
+
$this->state->save();
|
19 |
+
}
|
20 |
+
|
21 |
+
public function get_page_name() {
|
22 |
+
return 'submitlisting';
|
23 |
+
}
|
24 |
+
|
25 |
+
public function dispatch() {
|
26 |
+
// Check there are categories available
|
27 |
+
if ( count( get_terms(WPBDP_CATEGORY_TAX, array( 'hide_empty' => false) ) ) == 0 ) {
|
28 |
+
if ( current_user_can( 'administrator' ) ) {
|
29 |
+
return wpbdp_render_msg( _x( 'There are no categories assigned to the business directory yet. You need to assign some categories to the business directory. Only admins can see this message. Regular users are seeing a message that they cannot add their listing at this time. Listings cannot be added until you assign categories to the business directory.', 'templates', 'WPBDM' ), 'error' );
|
30 |
+
} else {
|
31 |
+
return wpbdp_render_msg( _x( 'Your listing cannot be added at this time. Please try again later. If this is not the first time you see this warning, please ask the site administrator to set up one or more categories inside the Directory.', 'templates', 'WPBDM' ), 'error' );
|
32 |
+
}
|
33 |
+
}
|
34 |
+
|
35 |
+
// Login required?
|
36 |
+
if ( wpbdp_get_option( 'require-login' ) && !is_user_logged_in() )
|
37 |
+
return wpbdp_render( 'parts/login-required', array(), false );
|
38 |
+
|
39 |
+
if ( $this->state->editing ) {
|
40 |
+
$current_user = wp_get_current_user();
|
41 |
+
|
42 |
+
if ( ( get_post( $this->state->listing_id )->post_author != $current_user->ID ) && ( !current_user_can( 'administrator' ) ) )
|
43 |
+
return wpbdp_render_msg( _x( 'You are not authorized to edit this listing.', 'templates', 'WPBDM' ), 'error' );
|
44 |
+
}
|
45 |
+
|
46 |
+
$callback = 'step_' . $this->state->step;
|
47 |
+
|
48 |
+
if ( method_exists( $this, $callback ) )
|
49 |
+
return call_user_func( array( &$this, $callback) );
|
50 |
+
else
|
51 |
+
return 'STEP NOT IMPLEMENTED YET: ' . $this->state->get_step();
|
52 |
+
}
|
53 |
+
|
54 |
+
protected function render( $template, $args = array(), $skipouter = false, $is_html = false ) {
|
55 |
+
$html = '';
|
56 |
+
$html .= sprintf( '<div id="wpbdp-submit-page" class="wpbdp-submit-page businessdirectory-submit businessdirectory wpbdp-page step-%s">',
|
57 |
+
str_replace( '_', '-', $this->state->step ) );
|
58 |
+
$html .= sprintf( '<h2>%s</h2>', $this->state->editing ? _x( 'Edit Your Listing', 'templates', 'WPBDM' ) : _x( 'Submit A Listing', 'templates', 'WPBDM' ) );
|
59 |
+
|
60 |
+
if ( current_user_can( 'administrator' ) ) {
|
61 |
+
if ( $errors = wpbdp_payments_api()->check_config() ) {
|
62 |
+
foreach ( $errors as $error ) $html .= wpbdp_render_msg( $error, 'error' );
|
63 |
+
}
|
64 |
+
|
65 |
+
$html .= wpbdp_render_msg( _x( 'You are logged in as an administrator. Any payment steps will be skipped.', 'templates', 'WPBDM' ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( $this->errors ) {
|
69 |
+
foreach ( $this->errors as &$e ) {
|
70 |
+
$html .= wpbdp_render_msg( $e, 'error' );
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( $this->messages ) {
|
75 |
+
foreach ( $this->messages as &$m ) {
|
76 |
+
$html .= wpbdp_render_msg( $m );
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( ! $is_html )
|
81 |
+
$content = wpbdp_render( 'submit-listing/' . $template,
|
82 |
+
array_merge( array( '_state' => $this->state ), $args ),
|
83 |
+
false );
|
84 |
+
else
|
85 |
+
$content = $template;
|
86 |
+
|
87 |
+
$html .= $content;
|
88 |
+
$html .= '</div>';
|
89 |
+
|
90 |
+
return apply_filters_ref_array( 'wpbdp_view_submit_listing', array( $html, &$this->state ) );
|
91 |
+
}
|
92 |
+
|
93 |
+
protected function step_category_selection() {
|
94 |
+
if ( $this->state->editing ) {
|
95 |
+
$this->state->advance( false );
|
96 |
+
return $this->dispatch();
|
97 |
+
}
|
98 |
+
|
99 |
+
$category_field = wpbdp_get_form_fields( 'association=category&unique=1' ) or die( '' );
|
100 |
+
|
101 |
+
$post_value = isset( $_POST['listingfields'][ $category_field->get_id() ] ) ?
|
102 |
+
$category_field->convert_input( $_POST['listingfields'][ $category_field->get_id() ] ) :
|
103 |
+
array();
|
104 |
+
if ( $post_value && ! is_array( $post_value ) )
|
105 |
+
$post_value = array( $post_value );
|
106 |
+
|
107 |
+
if ( $post_value ) {
|
108 |
+
$errors = null;
|
109 |
+
|
110 |
+
if ( ! $category_field->validate( $post_value, $errors ) ) {
|
111 |
+
$this->errors = array_merge( $this->errors, $errors );
|
112 |
+
} else {
|
113 |
+
$categories = array();
|
114 |
+
|
115 |
+
foreach ( $post_value as $category_id )
|
116 |
+
$categories[ $category_id ] = isset( $this->state->categories[ $category_id ] ) ? $this->state->categories[ $category_id ] : null;
|
117 |
+
|
118 |
+
$this->state->categories = $categories;
|
119 |
+
|
120 |
+
$this->state->advance();
|
121 |
+
return $this->dispatch();
|
122 |
+
}
|
123 |
+
|
124 |
+
}
|
125 |
+
|
126 |
+
return $this->render( 'category-selection', array( 'category_field' => $category_field ) );
|
127 |
+
}
|
128 |
+
|
129 |
+
private function skip_fee_selection( &$fee_selection ) {
|
130 |
+
if ( $this->state->editing )
|
131 |
+
return true;
|
132 |
+
|
133 |
+
$all_free_fees = true;
|
134 |
+
foreach ( $fee_selection as &$f ) {
|
135 |
+
if ( ( count( $f['options'] ) > 1 ) || ( $f['options'][0]->id != 0 ) ) {
|
136 |
+
$all_free_fees = false;
|
137 |
+
break;
|
138 |
+
}
|
139 |
+
}
|
140 |
+
|
141 |
+
return $all_free_fees && ( ! wpbdp_get_option( 'featured-on' ) || ! wpbdp_get_option( 'featured-offer-in-submit' ) );
|
142 |
+
}
|
143 |
+
|
144 |
+
private function setup_fee_selection() {
|
145 |
+
$fee_selection = array();
|
146 |
+
|
147 |
+
foreach ( $this->state->categories as $cat_id => $fee_id ) {
|
148 |
+
if ( $this->state->editing ) {
|
149 |
+
$fee_selection[ $cat_id ] = array( 'fee_id' => $fee_id );
|
150 |
+
} else {
|
151 |
+
if ( $term = get_term( $cat_id, WPBDP_CATEGORY_TAX ) ) {
|
152 |
+
$options = wpbdp_get_fees_for_category( $cat_id );
|
153 |
+
|
154 |
+
if ( count( $options ) > 1 || $options[0]->id != 0 ) {
|
155 |
+
$fee_selection[ $cat_id ] = array( 'fee_id' => isset( $_POST['fees'][ $cat_id ] ) ? $_POST['fees'][ $cat_id ] : $fee_id,
|
156 |
+
'term' => $term,
|
157 |
+
'options' => $options );
|
158 |
+
} else {
|
159 |
+
$fee_selection[ $cat_id ] = array( 'fee_id' => 0,
|
160 |
+
'term' => $term,
|
161 |
+
'options' => $options );
|
162 |
+
}
|
163 |
+
|
164 |
+
} else {
|
165 |
+
unset( $this->state->categories[ $cat_id ] );
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
return $fee_selection;
|
171 |
+
}
|
172 |
+
|
173 |
+
protected function step_fee_selection() {
|
174 |
+
global $wpbdp;
|
175 |
+
|
176 |
+
if ( ! $this->state->categories ) {
|
177 |
+
die();
|
178 |
+
}
|
179 |
+
|
180 |
+
$fee_selection = $this->setup_fee_selection();
|
181 |
+
|
182 |
+
if ( $this->skip_fee_selection( $fee_selection ) ) {
|
183 |
+
foreach ( array_keys( $this->state->categories ) as $cat_id )
|
184 |
+
$this->state->categories[ $cat_id ] = $fee_selection[ $cat_id ][ 'fee_id' ];
|
185 |
+
|
186 |
+
$this->state->upgrade_to_sticky = false;
|
187 |
+
|
188 |
+
$this->state->advance( false );
|
189 |
+
return $this->dispatch();
|
190 |
+
}
|
191 |
+
|
192 |
+
if ( isset( $_POST['fees'] ) ) {
|
193 |
+
$validates = true;
|
194 |
+
|
195 |
+
foreach ( array_keys( $this->state->categories ) as $cat_id) {
|
196 |
+
$selected_fee_id = wpbdp_getv( $_POST['fees'], $cat_id, null );
|
197 |
+
|
198 |
+
if ( null === $selected_fee_id ) {
|
199 |
+
$this->errors[] = sprintf( _x( 'Please select a fee option for the "%s" category.', 'templates', 'WPBDM' ), esc_html( $fee_selection[ $cat_id ]['term']->name ) );
|
200 |
+
$validates = false;
|
201 |
+
} else {
|
202 |
+
$this->state->categories[ $cat_id ] = $selected_fee_id;
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( $validates ) {
|
207 |
+
$this->state->upgrade_to_sticky = isset( $_POST['upgrade-listing'] ) && $_POST['upgrade-listing'] == 'upgrade' ? true : false;
|
208 |
+
$this->state->autorenew_fees = false;
|
209 |
+
|
210 |
+
if ( isset( $_POST['autorenew_fees'] ) && 'autorenew' == $_POST['autorenew_fees'] && 1 == count( $this->state->categories ) ) {
|
211 |
+
$fee = wpbdp_get_fee( end( $this->state->categories ) );
|
212 |
+
|
213 |
+
if ( $fee->amount > 0.0 && $fee->days > 0 )
|
214 |
+
$this->state->autorenew_fees = true;
|
215 |
+
}
|
216 |
+
|
217 |
+
$this->state->advance();
|
218 |
+
return $this->dispatch();
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
$upgrade_option = false;
|
223 |
+
if ( ! $this->state->editing && wpbdp_get_option( 'featured-on' ) && wpbdp_get_option( 'featured-offer-in-submit' ) ) {
|
224 |
+
$upgrade_option = wpbdp_listing_upgrades_api()->get( 'sticky' );
|
225 |
+
}
|
226 |
+
|
227 |
+
return $this->render( 'fee-selection', array(
|
228 |
+
'fee_selection' => $fee_selection,
|
229 |
+
'upgrade_option' => $upgrade_option,
|
230 |
+
'allow_recurring' => count( $this->state->categories ) <= 1 && wpbdp_get_option( 'listing-renewal-auto' ) && $wpbdp->payments->check_capability( 'recurring' )
|
231 |
+
) );
|
232 |
+
}
|
233 |
+
|
234 |
+
public function preview_listing_fields_form() {
|
235 |
+
return $this->step_listing_fields();
|
236 |
+
}
|
237 |
+
|
238 |
+
protected function step_listing_fields() {
|
239 |
+
$fields = wpbdp_get_form_fields( array( 'association' => '-category' ) );
|
240 |
+
$fields = apply_filters_ref_array( 'wpbdp_listing_submit_fields', array( &$fields, &$this->state ) );
|
241 |
+
|
242 |
+
$validation_errors = array();
|
243 |
+
if ( isset( $_POST['listingfields'] ) && isset( $_POST['step'] ) && 'listing_fields' == $_POST['step'] ) {
|
244 |
+
$_POST['listingfields'] = stripslashes_deep( $_POST['listingfields'] );
|
245 |
+
|
246 |
+
foreach ( $fields as &$f ) {
|
247 |
+
$value = $f->convert_input( wpbdp_getv( $_POST['listingfields'], $f->get_id(), null ) );
|
248 |
+
$this->state->fields[ $f->get_id() ] = $value;
|
249 |
+
|
250 |
+
$field_errors = null;
|
251 |
+
$validate_res = apply_filters_ref_array( 'wpbdp_listing_submit_validate_field', array(
|
252 |
+
$f->validate( $value, $field_errors ),
|
253 |
+
&$field_errors,
|
254 |
+
&$f,
|
255 |
+
$value,
|
256 |
+
&$this->state
|
257 |
+
) );
|
258 |
+
|
259 |
+
if ( !$validate_res )
|
260 |
+
$validation_errors = array_merge( $validation_errors, $field_errors );
|
261 |
+
}
|
262 |
+
|
263 |
+
if ( ! $this->state->editing && !current_user_can( 'administrator' ) && wpbdp_get_option( 'display-terms-and-conditions' ) ) {
|
264 |
+
$tos = trim( wpbdp_get_option( 'terms-and-conditions' ) );
|
265 |
+
|
266 |
+
if ( $tos && ( !isset( $_POST['terms-and-conditions-agreement'] ) || $_POST['terms-and-conditions-agreement'] != 1 ) ) {
|
267 |
+
$validation_errors[] = _x( 'Please agree to the Terms and Conditions.', 'templates', 'WPBDM' );
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( wpbdp_get_option( 'recaptcha-for-submits' ) ) {
|
272 |
+
if ( ! wpbdp_recaptcha_check_answer() )
|
273 |
+
$validation_errors[] = _x( "The reCAPTCHA wasn't entered correctly.", 'templates', 'WPBDM' );
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( !$validation_errors ) {
|
277 |
+
$this->state->advance();
|
278 |
+
return $this->dispatch();
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
$terms_field = '';
|
283 |
+
if ( ! $this->state->editing /*&& !current_user_can( 'administrator' ) */&& wpbdp_get_option( 'display-terms-and-conditions' ) ) {
|
284 |
+
$tos = trim( wpbdp_get_option( 'terms-and-conditions' ) );
|
285 |
+
|
286 |
+
if ( $tos ) {
|
287 |
+
if ( wpbdp_starts_with( $tos, 'http://', false ) || wpbdp_starts_with( $tos, 'https://', false ) ) {
|
288 |
+
$terms_field .= sprintf( '<a href="%s" target="_blank">%s</a>',
|
289 |
+
esc_url( $tos ),
|
290 |
+
_x( 'Read our Terms and Conditions', 'templates', 'WPBDM' )
|
291 |
+
);
|
292 |
+
} else {
|
293 |
+
$terms_field .= '<div class="wpbdp-form-field-label">';
|
294 |
+
$terms_field .= '<label>';
|
295 |
+
$terms_field .= _x( 'Terms and Conditions:', 'templates', 'WPBDM' );
|
296 |
+
$terms_field .= '</label>';
|
297 |
+
$terms_field .= '</div>';
|
298 |
+
$terms_field .= '<div class="wpbdp-form-field-html wpbdp-form-field-inner">';
|
299 |
+
$terms_field .= sprintf( '<textarea readonly="readonly" rows="5" cols="50">%s</textarea>',
|
300 |
+
esc_textarea( $tos ) );
|
301 |
+
$terms_field .= '</div>';
|
302 |
+
}
|
303 |
+
|
304 |
+
$terms_field .= '<label>';
|
305 |
+
$terms_field .= '<input type="checkbox" name="terms-and-conditions-agreement" value="1" />';
|
306 |
+
$terms_field .= _x( 'I agree to the Terms and Conditions', 'templates', 'WPBDM' );
|
307 |
+
$terms_field .= '</label>';
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
$recaptcha = '';
|
312 |
+
if ( wpbdp_get_option('recaptcha-for-submits') ) {
|
313 |
+
$recaptcha = wpbdp_recaptcha();
|
314 |
+
}
|
315 |
+
|
316 |
+
return $this->render( 'listing-fields',
|
317 |
+
array(
|
318 |
+
'fields' => $fields,
|
319 |
+
'validation_errors' => $validation_errors,
|
320 |
+
'recaptcha' => $recaptcha,
|
321 |
+
'terms_and_conditions' => $terms_field
|
322 |
+
)
|
323 |
+
);
|
324 |
+
}
|
325 |
+
|
326 |
+
protected function step_images() {
|
327 |
+
// Calculate image slots this listing can use.
|
328 |
+
$image_slots = 0;
|
329 |
+
|
330 |
+
if ( wpbdp_get_option( 'allow-images' ) ) {
|
331 |
+
foreach ( $this->state->categories as $cat_id => $fee_id )
|
332 |
+
$image_slots += wpbdp_get_fee( $fee_id )->images; // TODO: max() instead of + probably makes more sense here.
|
333 |
+
}
|
334 |
+
|
335 |
+
// Move on if there are no slots.
|
336 |
+
if ( 0 == $image_slots ) {
|
337 |
+
$this->state->advance( false );
|
338 |
+
return $this->dispatch();
|
339 |
+
}
|
340 |
+
|
341 |
+
$images = $this->state->images;
|
342 |
+
$thumbnail_id = $this->state->thumbnail_id;
|
343 |
+
$image_slots_remaining = $image_slots - count( $images );
|
344 |
+
$image_max_file_size = size_format( intval( wpbdp_get_option( 'image-max-filesize' ) ) * 1024 );
|
345 |
+
|
346 |
+
// Set thumbnail.
|
347 |
+
$thumbnail_id = isset( $_POST['thumbnail_id'] ) ? intval( $_POST['thumbnail_id'] ) : $this->state->thumbnail_id;
|
348 |
+
$this->state->thumbnail_id = $thumbnail_id;
|
349 |
+
|
350 |
+
if ( isset( $_POST['finish'] ) ) {
|
351 |
+
$this->state->advance();
|
352 |
+
return $this->dispatch();
|
353 |
+
}
|
354 |
+
|
355 |
+
return $this->render( 'images',
|
356 |
+
compact( 'image_max_file_size',
|
357 |
+
'images',
|
358 |
+
'image_slots',
|
359 |
+
'image_slots_remaining' )
|
360 |
+
);
|
361 |
+
}
|
362 |
+
|
363 |
+
protected function step_before_save() {
|
364 |
+
if ( isset( $_POST['continue-with-save'] ) ) {
|
365 |
+
$this->state->advance();
|
366 |
+
return $this->dispatch();
|
367 |
+
}
|
368 |
+
|
369 |
+
$extra = wpbdp_capture_action_array( 'wpbdp_listing_form_extra_sections', array( &$this->state ) );
|
370 |
+
$this->state->save(); // Save state in case extra sections modified it.
|
371 |
+
|
372 |
+
if ( !$extra ) {
|
373 |
+
$this->state->advance( false );
|
374 |
+
return $this->dispatch();
|
375 |
+
}
|
376 |
+
|
377 |
+
return $this->render( 'extra-sections', array( 'output' => $extra ) );
|
378 |
+
}
|
379 |
+
|
380 |
+
protected function step_save() {
|
381 |
+
$listing = $this->state->editing ? WPBDP_Listing::get( $this->state->listing_id ) : WPBDP_Listing::create( $this->state );
|
382 |
+
$listing->set_field_values( $this->state->fields );
|
383 |
+
$listing->set_images( $this->state->images );
|
384 |
+
$listing->set_thumbnail_id( $this->state->thumbnail_id );
|
385 |
+
|
386 |
+
if ( ! $this->state->editing ) {
|
387 |
+
// Generate payment for the listing.
|
388 |
+
$payment = new WPBDP_Payment( array( 'listing_id' => $listing->get_id() ) );
|
389 |
+
foreach ( $this->state->categories as $cat_id => $fee_id ) {
|
390 |
+
$category_info = $listing->get_category_info( $cat_id );
|
391 |
+
|
392 |
+
if ( ! $category_info ) {
|
393 |
+
$fee = wpbdp_get_fee( $fee_id );
|
394 |
+
|
395 |
+
if ( ! $fee )
|
396 |
+
continue;
|
397 |
+
|
398 |
+
$payment->add_item( $this->state->autorenew_fees ? 'recurring_fee' : 'fee',
|
399 |
+
$fee->amount,
|
400 |
+
sprintf( _x( 'Fee "%s" for category "%s"%s', 'listings', 'WPBDM' ),
|
401 |
+
$fee->label,
|
402 |
+
wpbdp_get_term_name( $cat_id ),
|
403 |
+
$this->state->autorenew_fees ? ( ' ' . _x( '(recurring)', 'listings', 'WPBDM' ) ) : '' ),
|
404 |
+
array( 'fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images ),
|
405 |
+
$cat_id,
|
406 |
+
$fee_id );
|
407 |
+
}
|
408 |
+
}
|
409 |
+
|
410 |
+
if ( $this->state->upgrade_to_sticky )
|
411 |
+
$payment->add_item( 'upgrade',
|
412 |
+
wpbdp_get_option( 'featured-price' ),
|
413 |
+
_x( 'Listing upgrade to featured', 'submit', 'WPBDM' ) );
|
414 |
+
|
415 |
+
$payment->set_submit_state_id( $this->state->id );
|
416 |
+
|
417 |
+
if ( current_user_can( 'administrator' ) )
|
418 |
+
$payment->set_status( WPBDP_Payment::STATUS_COMPLETED );
|
419 |
+
|
420 |
+
$payment->save();
|
421 |
+
|
422 |
+
$this->state->listing_id = $listing->get_id();
|
423 |
+
$this->state->payment_id = $payment->get_id();
|
424 |
+
}
|
425 |
+
|
426 |
+
do_action_ref_array( 'wpbdp_listing_form_extra_sections_save', array( &$this->state ) );
|
427 |
+
|
428 |
+
$listing->save();
|
429 |
+
$listing->set_post_status( $this->state->editing ? wpbdp_get_option( 'edit-post-status' ) : wpbdp_get_option( 'new-post-status' ) );
|
430 |
+
|
431 |
+
$this->state->advance( false ); // This step is 'invisible'.
|
432 |
+
return $this->dispatch();
|
433 |
+
}
|
434 |
+
|
435 |
+
protected function step_checkout() {
|
436 |
+
global $wpbdp;
|
437 |
+
|
438 |
+
if ( $this->state->editing ) {
|
439 |
+
$this->state->advance( false );
|
440 |
+
return $this->dispatch();
|
441 |
+
}
|
442 |
+
|
443 |
+
$payment = WPBDP_Payment::get( $this->state->payment_id );
|
444 |
+
|
445 |
+
if ( ! $payment )
|
446 |
+
return wpbdp_render_msg( _x( 'Invalid submit state.', 'submit_state', 'WPBDM' ), 'error' );
|
447 |
+
|
448 |
+
if ( $payment->is_completed() ) {
|
449 |
+
$this->state->advance( false );
|
450 |
+
return $this->dispatch();
|
451 |
+
}
|
452 |
+
|
453 |
+
require_once( WPBDP_PATH . 'core/view-checkout.php' );
|
454 |
+
$checkout = new WPBDP_Checkout_Page( $payment );
|
455 |
+
return $checkout->dispatch();
|
456 |
+
}
|
457 |
+
|
458 |
+
protected function step_confirmation() {
|
459 |
+
$listing = WPBDP_Listing::get( $this->state->listing_id );
|
460 |
+
$listing->notify( $this->state->editing ? 'edit' : 'new', $this->state );
|
461 |
+
return $this->render( 'done' );
|
462 |
+
}
|
463 |
+
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Lightweight object used to store the submit process advance.
|
468 |
+
* @since 3.3
|
469 |
+
*/
|
470 |
+
class WPBDP_Listing_Submit_State {
|
471 |
+
|
472 |
+
public static $STEPS = array( 'category_selection',
|
473 |
+
'fee_selection',
|
474 |
+
'listing_fields',
|
475 |
+
'images',
|
476 |
+
'before_save',
|
477 |
+
'save',
|
478 |
+
'checkout',
|
479 |
+
'confirmation' );
|
480 |
+
|
481 |
+
public $id = '';
|
482 |
+
public $listing_id = 0;
|
483 |
+
|
484 |
+
public $step_number = 1;
|
485 |
+
public $step = 'category_selection';
|
486 |
+
|
487 |
+
public $fields = array();
|
488 |
+
public $categories = array();
|
489 |
+
public $autorenew_fees = false;
|
490 |
+
public $upgrade_to_sticky = false;
|
491 |
+
public $extra = array();
|
492 |
+
public $editing = false;
|
493 |
+
|
494 |
+
public $images = array();
|
495 |
+
public $thumbnail_id = 0;
|
496 |
+
|
497 |
+
|
498 |
+
public function __construct( $listing_id = 0 ) {
|
499 |
+
$this->editing = $listing_id > 0 ? true : false;
|
500 |
+
|
501 |
+
if ( $listing_id > 0 ) {
|
502 |
+
$listing = WPBDP_Listing::get( $listing_id );
|
503 |
+
|
504 |
+
if ( ! $listing || ! $listing->is_published() )
|
505 |
+
throw new Exception( 'You can not edit this listing.' );
|
506 |
+
|
507 |
+
$this->listing_id = $listing_id;
|
508 |
+
|
509 |
+
$categories = $listing->get_categories( 'all' );
|
510 |
+
foreach ( $categories as &$category )
|
511 |
+
$this->categories[ $category->id ] = $category->fee_id;
|
512 |
+
|
513 |
+
// Image information.
|
514 |
+
$this->images = $listing->get_images( 'ids' );
|
515 |
+
$this->thumbnail_id = $listing->get_thumbnail_id();
|
516 |
+
|
517 |
+
// Fields.
|
518 |
+
$fields = wpbdp_get_form_fields( array( 'association' => '-category' ) );
|
519 |
+
foreach ( $fields as &$f ) {
|
520 |
+
$this->fields[ $f->get_id() ] = $f->value( $this->listing_id );
|
521 |
+
}
|
522 |
+
|
523 |
+
// Recover additional information.
|
524 |
+
do_action_ref_array( 'wpbdp_submit_state_init', array( &$this ) );
|
525 |
+
}
|
526 |
+
}
|
527 |
+
|
528 |
+
public static function &get( $id ) {
|
529 |
+
global $wpdb;
|
530 |
+
|
531 |
+
$state = wp_cache_get( $id, 'wpbdp submit state' );
|
532 |
+
|
533 |
+
if ( ! $state ) {
|
534 |
+
$row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wpbdp_submit_state WHERE id = %s", $id ) );
|
535 |
+
|
536 |
+
if ( ! $row )
|
537 |
+
return null;
|
538 |
+
|
539 |
+
$state = unserialize( $row->state );
|
540 |
+
|
541 |
+
$obj = new self;
|
542 |
+
foreach ( $state as $k => &$v )
|
543 |
+
$obj->{$k} = $v;
|
544 |
+
|
545 |
+
$state = $obj;
|
546 |
+
wp_cache_set( $id, $state, 'wpbdp submit state' );
|
547 |
+
}
|
548 |
+
|
549 |
+
return $state;
|
550 |
+
}
|
551 |
+
|
552 |
+
public function save() {
|
553 |
+
global $wpdb;
|
554 |
+
|
555 |
+
$this->id = $this->id ? $this->id : md5( microtime() . rand() . wp_salt() );
|
556 |
+
$data = array( 'id' => $this->id,
|
557 |
+
'state' => serialize( (array) $this ),
|
558 |
+
'updated_on' => current_time( 'mysql' ) );
|
559 |
+
$wpdb->replace( $wpdb->prefix . 'wpbdp_submit_state', $data );
|
560 |
+
}
|
561 |
+
|
562 |
+
public function advance( $increase_step_number = true ) {
|
563 |
+
$current_step = $this->step;
|
564 |
+
|
565 |
+
if ( 'confirmation' == $current_step )
|
566 |
+
return;
|
567 |
+
|
568 |
+
$current_index = array_search( $this->step, self::$STEPS );
|
569 |
+
$this->step = self::$STEPS[ ++$current_index ];
|
570 |
+
|
571 |
+
if ( $increase_step_number )
|
572 |
+
$this->step_number++;
|
573 |
+
|
574 |
+
$this->save();
|
575 |
+
}
|
576 |
+
}
|
core/view-upgrade-listing.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-view.php' );
|
3 |
+
|
4 |
+
class WPBDP_Upgrade_Listing_Page extends WPBDP_View {
|
5 |
+
|
6 |
+
private $listing = null;
|
7 |
+
private $upgrades_api = null;
|
8 |
+
|
9 |
+
public function __construct() {
|
10 |
+
$this->upgrades_api = wpbdp_listing_upgrades_api();
|
11 |
+
}
|
12 |
+
|
13 |
+
public function get_page_name() {
|
14 |
+
return 'upgradetostickylisting';
|
15 |
+
}
|
16 |
+
|
17 |
+
public function dispatch() {
|
18 |
+
$this->listing = WPBDP_Listing::get( intval( $_GET['listing_id'] ? $_GET['listing_id'] : 0 ) );
|
19 |
+
|
20 |
+
if ( ! $this->listing || ! wpbdp_user_can( 'upgrade-to-sticky', $this->listing->get_id() ) )
|
21 |
+
return wpbdp_render_msg( _x( 'Invalid link followed.', 'listing upgrade', 'WPBDM' ), 'error' );
|
22 |
+
|
23 |
+
$sticky_info = $this->upgrades_api->get_info( $this->listing->get_id() );
|
24 |
+
|
25 |
+
if ( $sticky_info->pending ) {
|
26 |
+
$html = '';
|
27 |
+
$html .= wpbdp_render_msg( _x( 'Your listing is already pending approval for "featured" status.', 'templates', 'WPBDM' ) );
|
28 |
+
$html .= sprintf('<a href="%s">%s</a>', $this->listing->get_permalink(), _x( 'Return to listing.', 'templates', 'WPBDM' ) );
|
29 |
+
return $html;
|
30 |
+
}
|
31 |
+
|
32 |
+
if ( isset( $_POST['do_upgrade'] ) )
|
33 |
+
return $this->checkout();
|
34 |
+
|
35 |
+
return $this->upgrade_selection();
|
36 |
+
}
|
37 |
+
|
38 |
+
private function upgrade_selection() {
|
39 |
+
$sticky_info = $this->upgrades_api->get_info( $this->listing->get_id() );
|
40 |
+
|
41 |
+
return wpbdp_render( 'listing-upgradetosticky', array( 'listing' => $this->listing,
|
42 |
+
'featured_level' => $sticky_info->upgrade ), false );
|
43 |
+
}
|
44 |
+
|
45 |
+
private function checkout() {
|
46 |
+
$sticky_info = $this->upgrades_api->get_info( $this->listing->get_id() );
|
47 |
+
|
48 |
+
if ( $sticky_info->pending || ! $sticky_info->upgradeable || ! wpbdp_payments_possible() )
|
49 |
+
return;
|
50 |
+
|
51 |
+
$payment = new WPBDP_Payment( array( 'listing_id' => $this->listing->get_id() ) );
|
52 |
+
$payment->add_item( 'upgrade',
|
53 |
+
$sticky_info->upgrade->cost,
|
54 |
+
_x( 'Listing upgrade to featured', 'submit', 'WPBDM' ) );
|
55 |
+
$payment->save();
|
56 |
+
update_post_meta( $this->listing->get_id(), '_wpbdp[sticky]', 'pending' ); // FIXME: maybe this should be set automatically when saving the payment?
|
57 |
+
|
58 |
+
require_once( WPBDP_PATH . 'core/view-checkout.php' );
|
59 |
+
$checkout = new WPBDP_Checkout_Page( $payment );
|
60 |
+
return $checkout->dispatch();
|
61 |
+
}
|
62 |
+
|
63 |
+
}
|
core/views.php
ADDED
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* General directory views
|
4 |
+
*/
|
5 |
+
|
6 |
+
if (!class_exists('WPBDP_DirectoryController')) {
|
7 |
+
|
8 |
+
class WPBDP_DirectoryController {
|
9 |
+
|
10 |
+
public $action = null;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
add_action( 'wp', array( $this, '_handle_action'), 10, 1 );
|
14 |
+
$this->_extra_sections = array();
|
15 |
+
}
|
16 |
+
|
17 |
+
public function check_main_page(&$msg) {
|
18 |
+
$msg = '';
|
19 |
+
|
20 |
+
$wpbdp = wpbdp();
|
21 |
+
if ( ! wpbdp_get_page_id( 'main' ) ) {
|
22 |
+
if (current_user_can('administrator') || current_user_can('activate_plugins'))
|
23 |
+
$msg = __('You need to create a page with the [businessdirectory] shortcode for the Business Directory plugin to work correctly.', 'WPBDM');
|
24 |
+
else
|
25 |
+
$msg = __('The directory is temporarily disabled.', 'WPBDM');
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
|
29 |
+
return true;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function _handle_action(&$wp) {
|
33 |
+
if ( is_page() && in_array( get_the_ID(), wpbdp_get_page_id( 'main', false ) ) ) {
|
34 |
+
$action = get_query_var('action') ? get_query_var('action') : ( isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '' );
|
35 |
+
|
36 |
+
if (get_query_var('category_id') || get_query_var('category')) $action = 'browsecategory';
|
37 |
+
if (get_query_var('tag')) $action = 'browsetag';
|
38 |
+
if (get_query_var('id') || get_query_var('listing')) $action = 'showlisting';
|
39 |
+
|
40 |
+
if (!$action) $action = 'main';
|
41 |
+
|
42 |
+
$this->action = $action;
|
43 |
+
} else {
|
44 |
+
$this->action = null;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
public function get_current_action() {
|
49 |
+
return $this->action;
|
50 |
+
}
|
51 |
+
|
52 |
+
public function dispatch() {
|
53 |
+
switch ($this->action) {
|
54 |
+
case 'showlisting':
|
55 |
+
return $this->show_listing();
|
56 |
+
break;
|
57 |
+
case 'browsecategory':
|
58 |
+
return $this->browse_category();
|
59 |
+
break;
|
60 |
+
case 'browsetag':
|
61 |
+
return $this->browse_tag();
|
62 |
+
break;
|
63 |
+
case 'editlisting':
|
64 |
+
case 'submitlisting':
|
65 |
+
require_once( WPBDP_PATH . 'core/view-submit-listing.php' );
|
66 |
+
$submit_page = new WPBDP_Submit_Listing_Page( isset( $_REQUEST['listing_id'] ) ? $_REQUEST['listing_id'] : 0 );
|
67 |
+
return $submit_page->dispatch();
|
68 |
+
|
69 |
+
break;
|
70 |
+
case 'sendcontactmessage':
|
71 |
+
require_once( WPBDP_PATH . 'core/view-listing-contact.php' );
|
72 |
+
$page = new WPBDP_Listing_Contact_View();
|
73 |
+
return $page->dispatch();
|
74 |
+
|
75 |
+
break;
|
76 |
+
case 'deletelisting':
|
77 |
+
require_once( WPBDP_PATH . 'core/view-delete-listing.php' );
|
78 |
+
$v = new WPBDP_Delete_Listing_View();
|
79 |
+
return $v->dispatch();
|
80 |
+
|
81 |
+
break;
|
82 |
+
case 'upgradetostickylisting':
|
83 |
+
require_once( WPBDP_PATH . 'core/view-upgrade-listing.php' );
|
84 |
+
$upgrade_page = new WPBDP_Upgrade_Listing_Page();
|
85 |
+
return $upgrade_page->dispatch();
|
86 |
+
|
87 |
+
break;
|
88 |
+
case 'viewlistings':
|
89 |
+
return $this->view_listings(true);
|
90 |
+
break;
|
91 |
+
case 'renewlisting':
|
92 |
+
require_once( WPBDP_PATH . 'core/view-renew-listing.php' );
|
93 |
+
$renew_page = new WPBDP_Renew_Listing_Page();
|
94 |
+
return $renew_page->dispatch();
|
95 |
+
|
96 |
+
break;
|
97 |
+
case 'payment-process':
|
98 |
+
return $this->process_payment();
|
99 |
+
break;
|
100 |
+
case 'search':
|
101 |
+
return $this->search();
|
102 |
+
break;
|
103 |
+
case 'checkout':
|
104 |
+
require_once( WPBDP_PATH . 'core/view-checkout.php' );
|
105 |
+
$checkout_page = new WPBDP_Checkout_Page();
|
106 |
+
return $checkout_page->dispatch();
|
107 |
+
break;
|
108 |
+
case 'manage-recurring':
|
109 |
+
require_once( WPBDP_PATH . 'core/view-manage-recurring.php' );
|
110 |
+
$page = new WPBDP_Manage_Subscriptions_View();
|
111 |
+
return $page->dispatch();
|
112 |
+
break;
|
113 |
+
default:
|
114 |
+
// Handle custom actions.
|
115 |
+
$page = wpbdp_capture_action_array( 'wpbdp_action_page_' . $this->action );
|
116 |
+
if ( $page )
|
117 |
+
return $page;
|
118 |
+
|
119 |
+
return $this->main_page();
|
120 |
+
break;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
/* Show listing. */
|
125 |
+
public function show_listing() {
|
126 |
+
if ( ! $this->check_main_page( $msg ) )
|
127 |
+
return $msg;
|
128 |
+
|
129 |
+
$id_or_slug = '';
|
130 |
+
if ( get_query_var( 'listing' ) || isset( $_GET['listing'] ) )
|
131 |
+
$id_or_slug = get_query_var( 'listing' ) ? get_query_var( 'listing' ) : wpbdp_getv( $_GET, 'listing', 0 );
|
132 |
+
else
|
133 |
+
$id_or_slug = get_query_var( 'id' ) ? get_query_var( 'id' ) : wpbdp_getv( $_GET, 'id', 0 );
|
134 |
+
|
135 |
+
$listing_id = wpbdp_get_post_by_id_or_slug( $id_or_slug, 'id', 'id' );
|
136 |
+
/*
|
137 |
+
if (get_query_var('listing') || isset($_GET['listing'])) {
|
138 |
+
if ($posts = get_posts(array('post_status' => 'any', 'numberposts' => 1, 'post_type' => WPBDP_POST_TYPE, 'name' => get_query_var('listing') ? get_query_var('listing') : wpbdp_getv($_GET, 'listing', null) ) )) {
|
139 |
+
$listing_id = $posts[0]->ID;
|
140 |
+
} else {
|
141 |
+
$listing_id = null;
|
142 |
+
}
|
143 |
+
} else {
|
144 |
+
$listing_id = get_query_var('id') ? get_query_var('id') : wpbdp_getv($_GET, 'id', null);
|
145 |
+
}*/
|
146 |
+
|
147 |
+
if ( !$listing_id )
|
148 |
+
return;
|
149 |
+
|
150 |
+
$html = '';
|
151 |
+
|
152 |
+
if ( 'publish' != get_post_status( $listing_id ) ) {
|
153 |
+
if ( current_user_can( 'edit_posts' ) )
|
154 |
+
$html .= wpbdp_render_msg( _x('This is just a preview. The listing has not been published yet.', 'preview', 'WPBDM') );
|
155 |
+
else
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
|
159 |
+
// Handle ?v=viewname argument for alternative views (other than 'single').
|
160 |
+
$view = '';
|
161 |
+
if ( isset( $_GET['v'] ) )
|
162 |
+
$view = wpbdp_capture_action_array( 'wpbdp_listing_view_' . trim( $_GET['v'] ), array( $listing_id ) );
|
163 |
+
|
164 |
+
if ( ! $view )
|
165 |
+
$html .= wpbdp_render_listing($listing_id, 'single', false, true);
|
166 |
+
else
|
167 |
+
$html .= $view;
|
168 |
+
|
169 |
+
return $html;
|
170 |
+
}
|
171 |
+
|
172 |
+
/* Display category. */
|
173 |
+
public function browse_category( $category_id=null, $args = array(), $in_listings_shortcode = false ) {
|
174 |
+
if (!$this->check_main_page($msg)) return $msg;
|
175 |
+
|
176 |
+
if (get_query_var('category')) {
|
177 |
+
if ($term = get_term_by('slug', get_query_var('category'), WPBDP_CATEGORY_TAX)) {
|
178 |
+
$category_id = $term->term_id;
|
179 |
+
} else {
|
180 |
+
$category_id = intval(get_query_var('category'));
|
181 |
+
}
|
182 |
+
}
|
183 |
+
|
184 |
+
$category_id = $category_id ? $category_id : intval(get_query_var('category_id'));
|
185 |
+
$category_id = is_array( $category_id ) && 1 == count( $category_id ) ? $category_id[0] : $category_id;
|
186 |
+
|
187 |
+
$listings_api = wpbdp_listings_api();
|
188 |
+
|
189 |
+
query_posts(array(
|
190 |
+
'post_type' => WPBDP_POST_TYPE,
|
191 |
+
'post_status' => 'publish',
|
192 |
+
'posts_per_page' => wpbdp_get_option( 'listings-per-page' ) > 0 ? wpbdp_get_option( 'listings-per-page' ) : -1,
|
193 |
+
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
|
194 |
+
'orderby' => wpbdp_get_option('listings-order-by', 'date'),
|
195 |
+
'order' => wpbdp_get_option('listings-sort', 'ASC'),
|
196 |
+
'tax_query' => array(
|
197 |
+
array('taxonomy' => WPBDP_CATEGORY_TAX,
|
198 |
+
'field' => 'id',
|
199 |
+
'terms' => $category_id)
|
200 |
+
)
|
201 |
+
));
|
202 |
+
|
203 |
+
if ( is_array( $category_id ) || $in_listings_shortcode ) {
|
204 |
+
$title = '';
|
205 |
+
$category = null;
|
206 |
+
} else {
|
207 |
+
$category = get_term( $category_id, WPBDP_CATEGORY_TAX );
|
208 |
+
$title = esc_attr( $category->name );
|
209 |
+
}
|
210 |
+
|
211 |
+
$html = wpbdp_render( 'category',
|
212 |
+
array(
|
213 |
+
'title' => $title,
|
214 |
+
'category' => $category,
|
215 |
+
'is_tag' => false
|
216 |
+
),
|
217 |
+
false );
|
218 |
+
|
219 |
+
wp_reset_query();
|
220 |
+
|
221 |
+
return $html;
|
222 |
+
}
|
223 |
+
|
224 |
+
/* Display category. */
|
225 |
+
public function browse_tag() {
|
226 |
+
if (!$this->check_main_page($msg)) return $msg;
|
227 |
+
|
228 |
+
$tag = get_term_by('slug', get_query_var('tag'), WPBDP_TAGS_TAX);
|
229 |
+
$tag_id = $tag->term_id;
|
230 |
+
|
231 |
+
$listings_api = wpbdp_listings_api();
|
232 |
+
|
233 |
+
query_posts(array(
|
234 |
+
'post_type' => WPBDP_POST_TYPE,
|
235 |
+
'post_status' => 'publish',
|
236 |
+
'posts_per_page' => wpbdp_get_option( 'listings-per-page' ) > 0 ? wpbdp_get_option( 'listings-per-page' ) : -1,
|
237 |
+
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
|
238 |
+
'orderby' => wpbdp_get_option('listings-order-by', 'date'),
|
239 |
+
'order' => wpbdp_get_option('listings-sort', 'ASC'),
|
240 |
+
'tax_query' => array(
|
241 |
+
array('taxonomy' => WPBDP_TAGS_TAX,
|
242 |
+
'field' => 'id',
|
243 |
+
'terms' => $tag_id)
|
244 |
+
)
|
245 |
+
));
|
246 |
+
|
247 |
+
$html = wpbdp_render( 'category',
|
248 |
+
array(
|
249 |
+
'title' => esc_attr( $tag->name ),
|
250 |
+
'category' => $tag,
|
251 |
+
'is_tag' => true
|
252 |
+
),
|
253 |
+
false );
|
254 |
+
|
255 |
+
wp_reset_query();
|
256 |
+
|
257 |
+
return $html;
|
258 |
+
}
|
259 |
+
|
260 |
+
/* display listings */
|
261 |
+
public function view_listings($include_buttons=false) {
|
262 |
+
$paged = 1;
|
263 |
+
|
264 |
+
if (get_query_var('page'))
|
265 |
+
$paged = get_query_var('page');
|
266 |
+
elseif (get_query_var('paged'))
|
267 |
+
$paged = get_query_var('paged');
|
268 |
+
|
269 |
+
query_posts(array(
|
270 |
+
'post_type' => WPBDP_POST_TYPE,
|
271 |
+
'posts_per_page' => wpbdp_get_option( 'listings-per-page' ) > 0 ? wpbdp_get_option( 'listings-per-page' ) : -1,
|
272 |
+
'post_status' => 'publish',
|
273 |
+
'paged' => intval($paged),
|
274 |
+
'orderby' => wpbdp_get_option('listings-order-by', 'date'),
|
275 |
+
'order' => wpbdp_get_option('listings-sort', 'ASC')
|
276 |
+
));
|
277 |
+
|
278 |
+
$html = wpbdp_capture_action( 'wpbdp_before_viewlistings_page' );
|
279 |
+
$html .= wpbdp_render('businessdirectory-listings', array(
|
280 |
+
'excludebuttons' => !$include_buttons
|
281 |
+
), true);
|
282 |
+
$html .= wpbdp_capture_action( 'wpbdp_after_viewlistings_page' );
|
283 |
+
|
284 |
+
wp_reset_query();
|
285 |
+
|
286 |
+
return $html;
|
287 |
+
}
|
288 |
+
|
289 |
+
/* display featured listings */
|
290 |
+
public function view_featured_listings($args) {
|
291 |
+
$no_listings = isset( $args['number_of_listings'] ) ? intval( $args['number_of_listings'] ) : 0;
|
292 |
+
|
293 |
+
if ( ! $no_listings )
|
294 |
+
$no_listings = wpbdp_get_option( 'listings-per-page' );
|
295 |
+
|
296 |
+
$html = '';
|
297 |
+
|
298 |
+
global $wp_query;
|
299 |
+
$old_query = $wp_query;
|
300 |
+
|
301 |
+
query_posts( array(
|
302 |
+
'post_type' => WPBDP_POST_TYPE,
|
303 |
+
'post_status' => 'publish',
|
304 |
+
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
|
305 |
+
'posts_per_page' => $no_listings,
|
306 |
+
'meta_query' => array(
|
307 |
+
array( 'key' => '_wpbdp[sticky]', 'value' => 'sticky' )
|
308 |
+
)
|
309 |
+
) );
|
310 |
+
|
311 |
+
$html = '';
|
312 |
+
$html .= wpbdp_render( 'businessdirectory-listings' );
|
313 |
+
|
314 |
+
$wp_query = $old_query;
|
315 |
+
wp_reset_query();
|
316 |
+
|
317 |
+
return $html;
|
318 |
+
}
|
319 |
+
|
320 |
+
public function submit_listing() {
|
321 |
+
require_once( WPBDP_PATH . 'core/view-submit-listing.php' );
|
322 |
+
$submit_page = new WPBDP_Submit_Listing_Page( isset( $_REQUEST['listing_id'] ) ? $_REQUEST['listing_id'] : 0 );
|
323 |
+
return $submit_page->dispatch();
|
324 |
+
}
|
325 |
+
|
326 |
+
/*
|
327 |
+
* Directory views/actions
|
328 |
+
*/
|
329 |
+
public function main_page() {
|
330 |
+
$html = '';
|
331 |
+
|
332 |
+
if ( count(get_terms(WPBDP_CATEGORY_TAX, array('hide_empty' => 0))) == 0 ) {
|
333 |
+
if (is_user_logged_in() && current_user_can('install_plugins')) {
|
334 |
+
$html .= wpbdp_render_msg( _x('There are no categories assigned to the business directory yet. You need to assign some categories to the business directory. Only admins can see this message. Regular users are seeing a message that there are currently no listings in the directory. Listings cannot be added until you assign categories to the business directory.', 'templates', 'WPBDM'), 'error' );
|
335 |
+
} else {
|
336 |
+
$html .= "<p>" . _x('There are currently no listings in the directory.', 'templates', 'WPBDM') . "</p>";
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
if (current_user_can('administrator')) {
|
341 |
+
if ($errors = wpbdp_payments_api()->check_config()) {
|
342 |
+
foreach ($errors as $error) {
|
343 |
+
$html .= wpbdp_render_msg($error, 'error');
|
344 |
+
}
|
345 |
+
}
|
346 |
+
}
|
347 |
+
|
348 |
+
$listings = '';
|
349 |
+
if (wpbdp_get_option('show-listings-under-categories'))
|
350 |
+
$listings = $this->view_listings(false);
|
351 |
+
|
352 |
+
if ( current_user_can( 'administrator' ) && wpbdp_get_option( 'hide-empty-categories' ) &&
|
353 |
+
wp_count_terms( WPBDP_CATEGORY_TAX, 'hide_empty=0' ) > 0 && wp_count_terms( WPBDP_CATEGORY_TAX, 'hide_empty=1' ) == 0 ) {
|
354 |
+
$msg = _x( 'You have "Hide Empty Categories" on and some categories that don\'t have listings in them. That means they won\'t show up on the front end of your site. If you didn\'t want that, click <a>here</a> to change the setting.',
|
355 |
+
'templates',
|
356 |
+
'WPBDM' );
|
357 |
+
$msg = str_replace( '<a>',
|
358 |
+
'<a href="' . admin_url( 'admin.php?page=wpbdp_admin_settings&groupid=listings#hide-empty-categories' ) . '">',
|
359 |
+
$msg );
|
360 |
+
$html .= wpbdp_render_msg( $msg );
|
361 |
+
}
|
362 |
+
|
363 |
+
$html .= wpbdp_render(array('businessdirectory-main-page', 'wpbusdirman-index-categories'),
|
364 |
+
array(
|
365 |
+
'submit_listing_button' => wpbusdirman_post_menu_button_submitlisting(),
|
366 |
+
'view_listings_button' => wpbusdirman_post_menu_button_viewlistings(),
|
367 |
+
'action_links' => wpbusdirman_post_menu_button_submitlisting() . wpbusdirman_post_menu_button_viewlistings(),
|
368 |
+
'search_form' => wpbdp_get_option('show-search-listings') ? wpbdp_search_form() : '',
|
369 |
+
'listings' => $listings
|
370 |
+
));
|
371 |
+
|
372 |
+
return $html;
|
373 |
+
}
|
374 |
+
|
375 |
+
|
376 |
+
/*
|
377 |
+
* Submit listing process.
|
378 |
+
*/
|
379 |
+
|
380 |
+
/* Manage Listings */
|
381 |
+
public function manage_listings() {
|
382 |
+
if (!$this->check_main_page($msg)) return $msg;
|
383 |
+
|
384 |
+
$current_user = is_user_logged_in() ? wp_get_current_user() : null;
|
385 |
+
$listings = array();
|
386 |
+
|
387 |
+
if ($current_user) {
|
388 |
+
query_posts(array(
|
389 |
+
'author' => $current_user->ID,
|
390 |
+
'post_type' => WPBDP_POST_TYPE,
|
391 |
+
'post_status' => 'publish',
|
392 |
+
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
|
393 |
+
));
|
394 |
+
}
|
395 |
+
|
396 |
+
$html = wpbdp_render('manage-listings', array(
|
397 |
+
'current_user' => $current_user
|
398 |
+
), false);
|
399 |
+
|
400 |
+
if ($current_user)
|
401 |
+
wp_reset_query();
|
402 |
+
|
403 |
+
return $html;
|
404 |
+
}
|
405 |
+
|
406 |
+
/*
|
407 |
+
* Search functionality
|
408 |
+
*/
|
409 |
+
public function search() {
|
410 |
+
$_REQUEST = stripslashes_deep( $_REQUEST );
|
411 |
+
|
412 |
+
$search_args = array();
|
413 |
+
$results = array();
|
414 |
+
|
415 |
+
if ( isset( $_GET['dosrch'] ) ) {
|
416 |
+
$search_args['q'] = wpbdp_getv($_GET, 'q', null);
|
417 |
+
$search_args['fields'] = array(); // standard search fields
|
418 |
+
$search_args['extra'] = array(); // search fields added by plugins
|
419 |
+
|
420 |
+
foreach ( wpbdp_getv( $_GET, 'listingfields', array() ) as $field_id => $field_search )
|
421 |
+
$search_args['fields'][] = array( 'field_id' => $field_id, 'q' => $field_search );
|
422 |
+
|
423 |
+
foreach ( wpbdp_getv( $_GET, '_x', array() ) as $label => $field )
|
424 |
+
$search_args['extra'][ $label ] = $field;
|
425 |
+
|
426 |
+
$listings_api = wpbdp_listings_api();
|
427 |
+
|
428 |
+
if ( $search_args['q'] && ! $search_args['fields'] && ! $search_args['extra'] )
|
429 |
+
$results = $listings_api->quick_search( $search_args['q'] );
|
430 |
+
else
|
431 |
+
$results = $listings_api->search( $search_args );
|
432 |
+
}
|
433 |
+
|
434 |
+
$form_fields = wpbdp_get_form_fields( array( 'display_flags' => 'search', 'validators' => '-email' ) );
|
435 |
+
$fields = '';
|
436 |
+
foreach ( $form_fields as &$field ) {
|
437 |
+
$field_value = isset( $_REQUEST['listingfields'] ) && isset( $_REQUEST['listingfields'][ $field->get_id() ] ) ? $field->convert_input( $_REQUEST['listingfields'][ $field->get_id() ] ) : $field->convert_input( null );
|
438 |
+
$fields .= $field->render( $field_value, 'search' );
|
439 |
+
}
|
440 |
+
|
441 |
+
$args = array(
|
442 |
+
'post_type' => WPBDP_POST_TYPE,
|
443 |
+
'posts_per_page' => wpbdp_get_option( 'listings-per-page' ) > 0 ? wpbdp_get_option( 'listings-per-page' ) : -1,
|
444 |
+
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
|
445 |
+
'post__in' => $results ? $results : array(0),
|
446 |
+
'orderby' => wpbdp_get_option( 'listings-order-by', 'date' ),
|
447 |
+
'order' => wpbdp_get_option( 'listings-sort', 'ASC' )
|
448 |
+
);
|
449 |
+
$args = apply_filters( 'wpbdp_search_query_posts_args', $args, $search_args );
|
450 |
+
query_posts( $args );
|
451 |
+
|
452 |
+
$html = wpbdp_render( 'search',
|
453 |
+
array(
|
454 |
+
'fields' => $fields,
|
455 |
+
'searching' => isset( $_GET['dosrch'] ) ? true : false,
|
456 |
+
'show_form' => !isset( $_GET['dosrch'] ) || wpbdp_get_option( 'show-search-form-in-results' )
|
457 |
+
),
|
458 |
+
false );
|
459 |
+
wp_reset_query();
|
460 |
+
|
461 |
+
return $html;
|
462 |
+
}
|
463 |
+
|
464 |
+
}
|
465 |
+
|
466 |
+
}
|
core/widget-featured-listings.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-listings-widget.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Featured listings widget.
|
6 |
+
* @since 2.1
|
7 |
+
*/
|
8 |
+
class WPBDP_FeaturedListingsWidget extends WPBDP_Listings_Widget {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
parent::__construct( _x( 'Business Directory - Featured Listings', 'widgets', 'WPBDM' ),
|
12 |
+
_x( 'Displays a list of the featured/sticky listings in the directory.', 'widgets', 'WPBDM' ) );
|
13 |
+
|
14 |
+
$this->set_default_option_value( 'title', _x( 'Featured Listings', 'widgets', 'WPBDM' ) );
|
15 |
+
}
|
16 |
+
|
17 |
+
protected function _form( $instance ) {
|
18 |
+
printf( '<p><input id="%s" name="%s" type="checkbox" value="1" %s /> <label for="%s">%s</label></p>',
|
19 |
+
$this->get_field_id( 'random_order' ),
|
20 |
+
$this->get_field_name( 'random_order' ),
|
21 |
+
( isset( $instance['random_order'] ) && $instance['random_order'] == 1 ) ? 'checked="checked"' : '',
|
22 |
+
$this->get_field_id( 'random_order' ),
|
23 |
+
_x( 'Display listings in random order', 'widgets', 'WPBDM' )
|
24 |
+
);
|
25 |
+
}
|
26 |
+
|
27 |
+
public function update( $new, $old ) {
|
28 |
+
$new = parent::update( $new, $old );
|
29 |
+
$new['random_order'] = intval( $new['random_order'] ) == 1 ? 1 : 0;
|
30 |
+
|
31 |
+
return $new;
|
32 |
+
}
|
33 |
+
|
34 |
+
public function get_listings( $instance ) {
|
35 |
+
return get_posts( array( 'post_type' => WPBDP_POST_TYPE,
|
36 |
+
'post_status' => 'publish',
|
37 |
+
'numberposts' => $instance['number_of_listings'],
|
38 |
+
'orderby' => ( isset( $instance['random_order'] ) && $instance['random_order'] ) ? 'rand' : 'date',
|
39 |
+
'meta_query' => array(
|
40 |
+
array( 'key' => '_wpbdp[sticky]', 'value' => 'sticky' )
|
41 |
+
) ) );
|
42 |
+
}
|
43 |
+
|
44 |
+
}
|
core/widget-latest-listings.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-listings-widget.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Latest listings widget.
|
6 |
+
* @since 2.1
|
7 |
+
*/
|
8 |
+
class WPBDP_LatestListingsWidget extends WPBDP_Listings_Widget {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
parent::__construct( _x( 'Business Directory - Latest Listings', 'widgets', 'WPBDM' ),
|
12 |
+
_x('Displays a list of the latest listings in the Business Directory.', 'widgets', 'WPBDM' ) );
|
13 |
+
|
14 |
+
$this->set_default_option_value( 'title', _x( 'Latest Listings', 'widgets', 'WPBDM' ) );
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_listings( $instance ) {
|
18 |
+
return get_posts( array( 'post_type' => WPBDP_POST_TYPE,
|
19 |
+
'post_status' => 'publish',
|
20 |
+
'numberposts' => $instance['number_of_listings'],
|
21 |
+
'orderby' => 'date' ) );
|
22 |
+
}
|
23 |
+
|
24 |
+
}
|
25 |
+
|
core/widget-random-listings.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once( WPBDP_PATH . 'core/class-listings-widget.php' );
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Random listings widget.
|
6 |
+
* @since 2.1
|
7 |
+
*/
|
8 |
+
class WPBDP_RandomListingsWidget extends WPBDP_Listings_Widget {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
parent::__construct( _x( 'Business Directory - Random Listings', 'widgets', 'WPBDM' ),
|
12 |
+
_x( 'Displays a list of random listings from the Business Directory.', 'widgets', 'WPBDM' ) );
|
13 |
+
|
14 |
+
$this->set_default_option_value( 'title', _x( 'Random Listings', 'widgets', 'WPBDM' ) );
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_listings( $instance ) {
|
18 |
+
return get_posts( array( 'post_type' => WPBDP_POST_TYPE,
|
19 |
+
'post_status' => 'publish',
|
20 |
+
'numberposts' => $instance['number_of_listings'],
|
21 |
+
'orderby' => 'rand' ) );
|
22 |
+
}
|
23 |
+
|
24 |
+
}
|
core/widget-search.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Search widget.
|
4 |
+
* @since 2.1.6
|
5 |
+
*/
|
6 |
+
class WPBDP_SearchWidget extends WP_Widget {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
parent::__construct(false,
|
10 |
+
_x('Business Directory - Search', 'widgets', 'WPBDM'),
|
11 |
+
array('description' => _x('Displays a search form to look for Business Directory listings.', 'widgets', 'WPBDM')));
|
12 |
+
}
|
13 |
+
|
14 |
+
public function form($instance) {
|
15 |
+
if (isset($instance['title']))
|
16 |
+
$title = $instance['title'];
|
17 |
+
else
|
18 |
+
$title = _x('Search the Business Directory', 'widgets', 'WPBDM');
|
19 |
+
|
20 |
+
echo sprintf('<p><label for="%s">%s</label> <input class="widefat" id="%s" name="%s" type="text" value="%s" /></p>',
|
21 |
+
$this->get_field_id('title'),
|
22 |
+
_x('Title:', 'widgets', 'WPBDM'),
|
23 |
+
$this->get_field_id('title'),
|
24 |
+
$this->get_field_name('title'),
|
25 |
+
esc_attr($title)
|
26 |
+
);
|
27 |
+
echo '<p>';
|
28 |
+
|
29 |
+
echo _x('Form Style:', 'widgets', 'WPBDM');
|
30 |
+
echo '<br/>';
|
31 |
+
echo sprintf('<input id="%s" name="%s" type="radio" value="%s" %s/> <label for="%s">%s</label>',
|
32 |
+
$this->get_field_id('use_basic_form'),
|
33 |
+
$this->get_field_name('form_mode'),
|
34 |
+
'basic',
|
35 |
+
wpbdp_getv($instance, 'form_mode', 'basic') == 'basic' ? 'checked="checked"' : '',
|
36 |
+
$this->get_field_id('use_basic_form'),
|
37 |
+
_x('Basic', 'widgets', 'WPBDM') );
|
38 |
+
echo ' ';
|
39 |
+
echo sprintf('<input id="%s" name="%s" type="radio" value="%s" %s/> <label for="%s">%s</label>',
|
40 |
+
$this->get_field_id('use_advanced_form'),
|
41 |
+
$this->get_field_name('form_mode'),
|
42 |
+
'advanced',
|
43 |
+
wpbdp_getv($instance, 'form_mode', 'basic') == 'advanced' ? 'checked="checked"' : '',
|
44 |
+
$this->get_field_id('use_advanced_form'),
|
45 |
+
_x('Advanced', 'widgets', 'WPBDM') );
|
46 |
+
echo '</p>';
|
47 |
+
|
48 |
+
echo '<p class="wpbdp-search-widget-advanced-settings">';
|
49 |
+
echo _x('Search Fields (advanced mode):', 'widgets', 'WPBDM') . '<br/>';
|
50 |
+
echo ' <span class="description">' . _x('Display the following fields in the form.', 'widgets', 'WPBDM') . '</span>';
|
51 |
+
|
52 |
+
$instance_fields = wpbdp_getv( $instance, 'search_fields', array() );
|
53 |
+
|
54 |
+
$api = wpbdp_formfields_api();
|
55 |
+
|
56 |
+
echo sprintf('<select name="%s[]" multiple="multiple">', $this->get_field_name('search_fields'));
|
57 |
+
|
58 |
+
foreach ( $api->get_fields() as $field ) {
|
59 |
+
if ( $field->display_in( 'search' ) ) {
|
60 |
+
echo sprintf( '<option value="%s" %s>%s</option>',
|
61 |
+
$field->get_id(),
|
62 |
+
( !$instance_fields || in_array( $field->get_id(), $instance_fields) ) ? 'selected="selected"' : '',
|
63 |
+
esc_attr( $field->get_label() ) );
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
echo '</select>';
|
68 |
+
echo '</p>';
|
69 |
+
}
|
70 |
+
|
71 |
+
public function update($new_instance, $old_instance) {
|
72 |
+
$new_instance['title'] = strip_tags($new_instance['title']);
|
73 |
+
$new_instance['form_mode'] = wpbdp_getv($new_instance, 'form_mode', 'basic');
|
74 |
+
$new_instance['search_fields'] = wpbdp_getv($new_instance, 'search_fields', array());
|
75 |
+
return $new_instance;
|
76 |
+
}
|
77 |
+
|
78 |
+
public function widget($args, $instance) {
|
79 |
+
extract($args);
|
80 |
+
$title = apply_filters( 'widget_title', $instance['title'] );
|
81 |
+
|
82 |
+
echo $before_widget;
|
83 |
+
if ( ! empty( $title ) ) echo $before_title . $title . $after_title;
|
84 |
+
|
85 |
+
echo sprintf('<form action="%s" method="GET">', wpbdp_get_page_link() );
|
86 |
+
echo '<input type="hidden" name="action" value="search" />';
|
87 |
+
echo sprintf('<input type="hidden" name="page_id" value="%s" />', wpbdp_get_page_id('main'));
|
88 |
+
echo '<input type="hidden" name="dosrch" value="1" />';
|
89 |
+
|
90 |
+
if (wpbdp_getv($instance, 'form_mode', 'basic') == 'advanced') {
|
91 |
+
$fields_api = wpbdp_formfields_api();
|
92 |
+
|
93 |
+
foreach ( $fields_api->get_fields() as $field ) {
|
94 |
+
if ( $field->display_in( 'search' ) && in_array( $field->get_id(), $instance['search_fields'] ) ) {
|
95 |
+
echo $field->render( null, 'search' );
|
96 |
+
}
|
97 |
+
}
|
98 |
+
} else {
|
99 |
+
echo '<input type="text" name="q" value="" />';
|
100 |
+
}
|
101 |
+
|
102 |
+
echo sprintf('<p><input type="submit" value="%s" class="submit wpbdp-search-widget-submit" /></p>', _x('Search', 'widgets', 'WPBDM'));
|
103 |
+
echo '</form>';
|
104 |
+
|
105 |
+
echo $after_widget;
|
106 |
+
}
|
107 |
+
|
108 |
+
}
|
index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php
|
languages/WPBDM-en_US.mo
ADDED
Binary file
|
languages/WPBDM-en_US.po
ADDED
@@ -0,0 +1,5331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2013
|
2 |
+
# This file is distributed under the same license as the package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Business Directory Plugin 3.5.4\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/business-directory-plugin\n"
|
7 |
+
"POT-Creation-Date: 2015-01-06 02:44:52+00:00\n"
|
8 |
+
"PO-Revision-Date: 2015-01-05 22:13-0500\n"
|
9 |
+
"Last-Translator: BD Team <support@businessdirectoryplugin.com>\n"
|
10 |
+
"Language-Team: Business Directory Plugin <support@businessdirectoryplugin."
|
11 |
+
"com>\n"
|
12 |
+
"Language: en_US\n"
|
13 |
+
"MIME-Version: 1.0\n"
|
14 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
15 |
+
"Content-Transfer-Encoding: 8bit\n"
|
16 |
+
"X-Generator: Poedit 1.7.1\n"
|
17 |
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
18 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
19 |
+
|
20 |
+
#: admin/class-admin-listings.php:24
|
21 |
+
msgid "Listing Information"
|
22 |
+
msgstr ""
|
23 |
+
|
24 |
+
#: admin/class-admin-listings.php:31
|
25 |
+
msgctxt "admin"
|
26 |
+
msgid "Listing Fields / Images"
|
27 |
+
msgstr ""
|
28 |
+
|
29 |
+
#: admin/class-admin-listings.php:42
|
30 |
+
msgctxt "admin"
|
31 |
+
msgid "Categories"
|
32 |
+
msgstr ""
|
33 |
+
|
34 |
+
#: admin/class-admin-listings.php:43
|
35 |
+
msgid "Payment Status"
|
36 |
+
msgstr ""
|
37 |
+
|
38 |
+
#: admin/class-admin-listings.php:44
|
39 |
+
msgid "Featured (Sticky) Status"
|
40 |
+
msgstr ""
|
41 |
+
|
42 |
+
#: admin/class-admin-listings.php:75
|
43 |
+
msgctxt "admin"
|
44 |
+
msgid "(Listing expired in this category)"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: admin/class-admin-listings.php:93 admin/class-admin-listings.php:176
|
48 |
+
msgid "Paid"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: admin/class-admin-listings.php:98
|
52 |
+
msgid "Mark as"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: admin/class-admin-listings.php:107 admin/class-admin-listings.php:186
|
56 |
+
msgid "Pending Upgrade"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: admin/class-admin-listings.php:115 admin/listing-metabox.php:68
|
60 |
+
msgid "Upgrade to %s"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: admin/class-admin-listings.php:122 admin/listing-metabox.php:75
|
64 |
+
msgid "Downgrade to %s"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: admin/class-admin-listings.php:125 admin/class-admin-listings.php:295
|
68 |
+
msgctxt "admin actions"
|
69 |
+
msgid "Upgrade to Featured"
|
70 |
+
msgstr ""
|
71 |
+
|
72 |
+
#: admin/class-admin-listings.php:181
|
73 |
+
msgid "Unpaid"
|
74 |
+
msgstr ""
|
75 |
+
|
76 |
+
#: admin/class-admin-listings.php:191
|
77 |
+
msgctxt "admin"
|
78 |
+
msgid "Expired"
|
79 |
+
msgstr ""
|
80 |
+
|
81 |
+
#: admin/class-admin-listings.php:241
|
82 |
+
msgctxt "admin actions"
|
83 |
+
msgid "Edit Listing"
|
84 |
+
msgstr ""
|
85 |
+
|
86 |
+
#: admin/class-admin-listings.php:244
|
87 |
+
msgctxt "admin actions"
|
88 |
+
msgid "Delete Listing"
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: admin/class-admin-listings.php:293
|
92 |
+
msgctxt "admin actions"
|
93 |
+
msgid "Publish Listing"
|
94 |
+
msgstr ""
|
95 |
+
|
96 |
+
#: admin/class-admin-listings.php:296
|
97 |
+
msgctxt "admin actions"
|
98 |
+
msgid "Downgrade to Normal"
|
99 |
+
msgstr ""
|
100 |
+
|
101 |
+
#: admin/class-admin-listings.php:298
|
102 |
+
msgctxt "admin actions"
|
103 |
+
msgid "Mark as Paid"
|
104 |
+
msgstr ""
|
105 |
+
|
106 |
+
#: admin/class-admin-listings.php:300
|
107 |
+
msgctxt "admin actions"
|
108 |
+
msgid "Renew Listing"
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#: admin/class-admin.php:135
|
112 |
+
msgctxt "drip pointer"
|
113 |
+
msgid ""
|
114 |
+
"Find out how to create a compelling, thriving business directory from "
|
115 |
+
"scratch in this ridiculously actionable (and FREE) 5-part email course. Get "
|
116 |
+
"a FREE premium module just for signing up."
|
117 |
+
msgstr ""
|
118 |
+
|
119 |
+
#: admin/class-admin.php:137
|
120 |
+
msgctxt "drip pointer"
|
121 |
+
msgid "Email Address:"
|
122 |
+
msgstr ""
|
123 |
+
|
124 |
+
#: admin/class-admin.php:143
|
125 |
+
msgctxt "drip pointer"
|
126 |
+
msgid "Want to know the Secrets of Building an Awesome Business Directory?"
|
127 |
+
msgstr ""
|
128 |
+
|
129 |
+
#: admin/class-admin.php:145
|
130 |
+
msgctxt "drip pointer"
|
131 |
+
msgid "Yes, please!"
|
132 |
+
msgstr ""
|
133 |
+
|
134 |
+
#: admin/class-admin.php:147
|
135 |
+
msgctxt "drip pointer"
|
136 |
+
msgid "No, thanks"
|
137 |
+
msgstr ""
|
138 |
+
|
139 |
+
#: admin/class-admin.php:164
|
140 |
+
msgctxt "admin"
|
141 |
+
msgid "Business Directory"
|
142 |
+
msgstr ""
|
143 |
+
|
144 |
+
#: admin/class-admin.php:175
|
145 |
+
msgctxt "admin"
|
146 |
+
msgid "You're all set. Visit your new <a>Business Directory</a> page."
|
147 |
+
msgstr ""
|
148 |
+
|
149 |
+
#: admin/class-admin.php:235
|
150 |
+
msgctxt "admin menu"
|
151 |
+
msgid "Business Directory Admin"
|
152 |
+
msgstr ""
|
153 |
+
|
154 |
+
#: admin/class-admin.php:236
|
155 |
+
msgctxt "admin menu"
|
156 |
+
msgid "Directory Admin"
|
157 |
+
msgstr ""
|
158 |
+
|
159 |
+
#: admin/class-admin.php:242 admin/class-admin.php:243
|
160 |
+
msgctxt "admin menu"
|
161 |
+
msgid "Add New Listing"
|
162 |
+
msgstr ""
|
163 |
+
|
164 |
+
#: admin/class-admin.php:248 admin/class-admin.php:249
|
165 |
+
msgctxt "admin menu"
|
166 |
+
msgid "Manage Options"
|
167 |
+
msgstr ""
|
168 |
+
|
169 |
+
#: admin/class-admin.php:254 admin/class-admin.php:255
|
170 |
+
msgctxt "admin menu"
|
171 |
+
msgid "Manage Fees"
|
172 |
+
msgstr ""
|
173 |
+
|
174 |
+
#: admin/class-admin.php:260 admin/class-admin.php:261
|
175 |
+
msgctxt "admin menu"
|
176 |
+
msgid "Manage Form Fields"
|
177 |
+
msgstr ""
|
178 |
+
|
179 |
+
#: admin/class-admin.php:266 admin/class-admin.php:267
|
180 |
+
msgctxt "admin menu"
|
181 |
+
msgid "All Listings"
|
182 |
+
msgstr ""
|
183 |
+
|
184 |
+
#: admin/class-admin.php:272 admin/class-admin.php:273
|
185 |
+
msgctxt "admin menu"
|
186 |
+
msgid "Pending Upgrade"
|
187 |
+
msgstr ""
|
188 |
+
|
189 |
+
#: admin/class-admin.php:278 admin/class-admin.php:279
|
190 |
+
msgctxt "admin menu"
|
191 |
+
msgid "Pending Payment"
|
192 |
+
msgstr ""
|
193 |
+
|
194 |
+
#: admin/class-admin.php:294 admin/class-admin.php:295
|
195 |
+
msgctxt "admin menu"
|
196 |
+
msgid "CSV Import"
|
197 |
+
msgstr ""
|
198 |
+
|
199 |
+
#: admin/class-admin.php:300 admin/class-admin.php:301
|
200 |
+
msgctxt "admin menu"
|
201 |
+
msgid "CSV Export"
|
202 |
+
msgstr ""
|
203 |
+
|
204 |
+
#: admin/class-admin.php:306 admin/class-admin.php:307
|
205 |
+
msgctxt "admin menu"
|
206 |
+
msgid "Debug"
|
207 |
+
msgstr ""
|
208 |
+
|
209 |
+
#: admin/class-admin.php:316
|
210 |
+
msgctxt "admin menu"
|
211 |
+
msgid "Main Menu"
|
212 |
+
msgstr ""
|
213 |
+
|
214 |
+
#: admin/class-admin.php:329
|
215 |
+
msgctxt "admin menu"
|
216 |
+
msgid "Uninstall Business Directory Plugin"
|
217 |
+
msgstr ""
|
218 |
+
|
219 |
+
#: admin/class-admin.php:330
|
220 |
+
msgctxt "admin menu"
|
221 |
+
msgid "Uninstall"
|
222 |
+
msgstr ""
|
223 |
+
|
224 |
+
#: admin/class-admin.php:515
|
225 |
+
msgctxt "admin"
|
226 |
+
msgid "The listing has been published."
|
227 |
+
msgid_plural "The listings have been published."
|
228 |
+
msgstr[0] ""
|
229 |
+
msgstr[1] ""
|
230 |
+
|
231 |
+
#: admin/class-admin.php:528
|
232 |
+
msgctxt "admin"
|
233 |
+
msgid "The listing status has been set as paid."
|
234 |
+
msgid_plural "The listings status has been set as paid."
|
235 |
+
msgstr[0] ""
|
236 |
+
msgstr[1] ""
|
237 |
+
|
238 |
+
#: admin/class-admin.php:540
|
239 |
+
msgctxt "admin"
|
240 |
+
msgid "The listing has been modified."
|
241 |
+
msgid_plural "The listings have been modified."
|
242 |
+
msgstr[0] ""
|
243 |
+
msgstr[1] ""
|
244 |
+
|
245 |
+
#: admin/class-admin.php:553
|
246 |
+
msgctxt "admin"
|
247 |
+
msgid "The listing has been upgraded."
|
248 |
+
msgid_plural "The listings have been upgraded."
|
249 |
+
msgstr[0] ""
|
250 |
+
msgstr[1] ""
|
251 |
+
|
252 |
+
#: admin/class-admin.php:565
|
253 |
+
msgctxt "admin"
|
254 |
+
msgid "The listing has been downgraded."
|
255 |
+
msgid_plural "The listings have been downgraded."
|
256 |
+
msgstr[0] ""
|
257 |
+
msgstr[1] ""
|
258 |
+
|
259 |
+
#: admin/class-admin.php:577 admin/transactions.php:243
|
260 |
+
msgctxt "admin"
|
261 |
+
msgid "The transaction has been approved."
|
262 |
+
msgstr ""
|
263 |
+
|
264 |
+
#: admin/class-admin.php:585 admin/transactions.php:254
|
265 |
+
msgctxt "admin"
|
266 |
+
msgid "The transaction has been rejected."
|
267 |
+
msgstr ""
|
268 |
+
|
269 |
+
#: admin/class-admin.php:591
|
270 |
+
msgctxt "admin"
|
271 |
+
msgid "The fee was successfully assigned."
|
272 |
+
msgstr ""
|
273 |
+
|
274 |
+
#: admin/class-admin.php:600
|
275 |
+
msgctxt "admin"
|
276 |
+
msgid "Listing was renewed."
|
277 |
+
msgid_plural "Listings were renewed."
|
278 |
+
msgstr[0] ""
|
279 |
+
msgstr[1] ""
|
280 |
+
|
281 |
+
#: admin/class-admin.php:607
|
282 |
+
msgctxt "admin"
|
283 |
+
msgid "Renewal email sent."
|
284 |
+
msgstr ""
|
285 |
+
|
286 |
+
#: admin/class-admin.php:641
|
287 |
+
msgctxt "admin category id"
|
288 |
+
msgid "ID"
|
289 |
+
msgstr ""
|
290 |
+
|
291 |
+
#: admin/class-admin.php:643 admin/class-admin.php:649
|
292 |
+
msgctxt "admin"
|
293 |
+
msgid "Listing Count"
|
294 |
+
msgstr ""
|
295 |
+
|
296 |
+
#: admin/class-admin.php:745
|
297 |
+
msgctxt "admin"
|
298 |
+
msgid ""
|
299 |
+
"<b>Business Directory Plugin</b> requires fields with the following "
|
300 |
+
"associations in order to work correctly: <b>%s</b>."
|
301 |
+
msgstr ""
|
302 |
+
|
303 |
+
#: admin/class-admin.php:747
|
304 |
+
msgctxt "admin"
|
305 |
+
msgid ""
|
306 |
+
"<b>Business Directory Plugin</b> requires a field with a <b>%s</b> "
|
307 |
+
"association in order to work correctly."
|
308 |
+
msgstr ""
|
309 |
+
|
310 |
+
#: admin/class-admin.php:751
|
311 |
+
msgctxt "admin"
|
312 |
+
msgid ""
|
313 |
+
"You can create these custom fields by yourself inside \"Manage Form Fields\" "
|
314 |
+
"or let Business Directory do this for you automatically."
|
315 |
+
msgstr ""
|
316 |
+
|
317 |
+
#: admin/class-admin.php:755
|
318 |
+
msgctxt "admin"
|
319 |
+
msgid "Go to \"Manage Form Fields\""
|
320 |
+
msgstr ""
|
321 |
+
|
322 |
+
#: admin/class-admin.php:758
|
323 |
+
msgctxt "admin"
|
324 |
+
msgid "Create these required fields for me"
|
325 |
+
msgstr ""
|
326 |
+
|
327 |
+
#: admin/class-admin.php:767
|
328 |
+
msgctxt "admin"
|
329 |
+
msgid ""
|
330 |
+
"<b>Business Directory Plugin</b> requires a page with the "
|
331 |
+
"<tt>[businessdirectory]</tt> shortcode to function properly."
|
332 |
+
msgstr ""
|
333 |
+
|
334 |
+
#: admin/class-admin.php:769
|
335 |
+
msgctxt "admin"
|
336 |
+
msgid ""
|
337 |
+
"You can create this page by yourself or let Business Directory do this for "
|
338 |
+
"you automatically."
|
339 |
+
msgstr ""
|
340 |
+
|
341 |
+
#: admin/class-admin.php:773
|
342 |
+
msgctxt "admin"
|
343 |
+
msgid "Create required pages for me"
|
344 |
+
msgstr ""
|
345 |
+
|
346 |
+
#: admin/class-admin.php:803
|
347 |
+
msgctxt "admin compat"
|
348 |
+
msgid "Installed: %s"
|
349 |
+
msgstr ""
|
350 |
+
|
351 |
+
#: admin/class-admin.php:803
|
352 |
+
msgctxt "admin compat"
|
353 |
+
msgid "N/A"
|
354 |
+
msgstr ""
|
355 |
+
|
356 |
+
#: admin/class-admin.php:806
|
357 |
+
msgctxt "admin compat"
|
358 |
+
msgid "Required: %s"
|
359 |
+
msgstr ""
|
360 |
+
|
361 |
+
#: admin/class-admin.php:819
|
362 |
+
msgctxt "admin compat"
|
363 |
+
msgid ""
|
364 |
+
"Business Directory has detected some incompatible premium module versions "
|
365 |
+
"installed."
|
366 |
+
msgstr ""
|
367 |
+
|
368 |
+
#: admin/class-admin.php:821
|
369 |
+
msgctxt "admin compat"
|
370 |
+
msgid ""
|
371 |
+
"Please upgrade to the required versions indicated below to make sure "
|
372 |
+
"everything functions properly."
|
373 |
+
msgstr ""
|
374 |
+
|
375 |
+
#: admin/class-admin.php:836
|
376 |
+
msgctxt "admin"
|
377 |
+
msgid ""
|
378 |
+
"We noticed you want your Business Directory users to register before posting "
|
379 |
+
"listings, but Registration for your site is currently disabled. Go [here] "
|
380 |
+
"and check \"Anyone can register\" to make sure BD works properly."
|
381 |
+
msgstr ""
|
382 |
+
|
383 |
+
#: admin/class-listing-fields-metabox.php:21
|
384 |
+
msgctxt "admin"
|
385 |
+
msgid "Listing Fields"
|
386 |
+
msgstr ""
|
387 |
+
|
388 |
+
#: admin/class-listing-fields-metabox.php:40
|
389 |
+
#: templates/submit-listing/images.tpl.php:12
|
390 |
+
msgctxt "templates"
|
391 |
+
msgid "Current Images"
|
392 |
+
msgstr ""
|
393 |
+
|
394 |
+
#: admin/class-listing-fields-metabox.php:41
|
395 |
+
msgctxt "templates"
|
396 |
+
msgid "There are no images currently attached to the listing."
|
397 |
+
msgstr ""
|
398 |
+
|
399 |
+
#: admin/csv-export.php:136
|
400 |
+
msgctxt "admin csv-export"
|
401 |
+
msgid "Could not create a temporary directory for handling this CSV export."
|
402 |
+
msgstr ""
|
403 |
+
|
404 |
+
#: admin/csv-export.php:138
|
405 |
+
msgctxt "admin csv-export"
|
406 |
+
msgid "Could not create wpbdp-csv-exports directory."
|
407 |
+
msgstr ""
|
408 |
+
|
409 |
+
#: admin/csv-export.php:143
|
410 |
+
msgctxt "admin csv-export"
|
411 |
+
msgid "Error while creating a temporary directory for CSV export: %s"
|
412 |
+
msgstr ""
|
413 |
+
|
414 |
+
#: admin/csv-import.php:39
|
415 |
+
msgctxt "admin csv-import"
|
416 |
+
msgid "Business %s"
|
417 |
+
msgstr ""
|
418 |
+
|
419 |
+
#: admin/csv-import.php:77
|
420 |
+
msgctxt "admin csv-import"
|
421 |
+
msgid "Whatever"
|
422 |
+
msgstr ""
|
423 |
+
|
424 |
+
#: admin/csv-import.php:81
|
425 |
+
msgctxt "admin csv-import"
|
426 |
+
msgid "Example CSV Import File"
|
427 |
+
msgstr ""
|
428 |
+
|
429 |
+
#: admin/csv-import.php:82
|
430 |
+
msgctxt "admin csv-import"
|
431 |
+
msgid "← Return to \"CSV Import\""
|
432 |
+
msgstr ""
|
433 |
+
|
434 |
+
#: admin/csv-import.php:140
|
435 |
+
msgid ""
|
436 |
+
"A valid temporary directory with write permissions is required for CSV "
|
437 |
+
"imports to function properly. Your server is using \"%s\" but this path does "
|
438 |
+
"not seem to be writable. Please consult with your host."
|
439 |
+
msgstr ""
|
440 |
+
|
441 |
+
#: admin/csv-import.php:154
|
442 |
+
msgctxt "admin csv-import"
|
443 |
+
msgid "There was an error uploading the CSV file."
|
444 |
+
msgstr ""
|
445 |
+
|
446 |
+
#: admin/csv-import.php:160
|
447 |
+
msgctxt "admin csv-import"
|
448 |
+
msgid "The uploaded file does not look like a CSV file."
|
449 |
+
msgstr ""
|
450 |
+
|
451 |
+
#: admin/csv-import.php:178
|
452 |
+
msgctxt "admin csv-import"
|
453 |
+
msgid ""
|
454 |
+
"* Import is in test mode. Nothing was actually inserted into the database. *"
|
455 |
+
msgstr ""
|
456 |
+
|
457 |
+
#: admin/csv-import.php:185
|
458 |
+
msgctxt "admin csv-import"
|
459 |
+
msgid "Fatal errors encountered. Import will not proceed."
|
460 |
+
msgstr ""
|
461 |
+
|
462 |
+
#: admin/csv-import.php:189
|
463 |
+
msgctxt "admin csv-import"
|
464 |
+
msgid "Import was completed but some rows were rejected."
|
465 |
+
msgstr ""
|
466 |
+
|
467 |
+
#: admin/csv-import.php:191
|
468 |
+
msgctxt "admin csv-import"
|
469 |
+
msgid "Import was completed successfully."
|
470 |
+
msgstr ""
|
471 |
+
|
472 |
+
#: admin/csv-import.php:196
|
473 |
+
msgctxt "admin csv-import"
|
474 |
+
msgid "Import Summary"
|
475 |
+
msgstr ""
|
476 |
+
|
477 |
+
#: admin/csv-import.php:198
|
478 |
+
msgctxt "admin csv-import"
|
479 |
+
msgid "Correctly imported rows:"
|
480 |
+
msgstr ""
|
481 |
+
|
482 |
+
#: admin/csv-import.php:200
|
483 |
+
msgctxt "admin csv-import"
|
484 |
+
msgid "Rejected rows:"
|
485 |
+
msgstr ""
|
486 |
+
|
487 |
+
#: admin/csv-import.php:205
|
488 |
+
msgctxt "admin csv-import"
|
489 |
+
msgid "Rejected Rows"
|
490 |
+
msgstr ""
|
491 |
+
|
492 |
+
#: admin/csv-import.php:208 admin/csv-import.php:233
|
493 |
+
msgctxt "admin csv-import"
|
494 |
+
msgid "Line #"
|
495 |
+
msgstr ""
|
496 |
+
|
497 |
+
#: admin/csv-import.php:209 admin/csv-import.php:234
|
498 |
+
msgctxt "admin csv-import"
|
499 |
+
msgid "Line"
|
500 |
+
msgstr ""
|
501 |
+
|
502 |
+
#: admin/csv-import.php:210
|
503 |
+
msgctxt "admin csv-import"
|
504 |
+
msgid "Error"
|
505 |
+
msgstr ""
|
506 |
+
|
507 |
+
#: admin/csv-import.php:230
|
508 |
+
msgctxt "admin csv-import"
|
509 |
+
msgid "Import warnings (not critical)"
|
510 |
+
msgstr ""
|
511 |
+
|
512 |
+
#: admin/csv-import.php:235
|
513 |
+
msgctxt "admin csv-import"
|
514 |
+
msgid "Warning"
|
515 |
+
msgstr ""
|
516 |
+
|
517 |
+
#: admin/csv-import.php:390
|
518 |
+
msgctxt "admin csv-import"
|
519 |
+
msgid "Missing required header column: %s"
|
520 |
+
msgstr ""
|
521 |
+
|
522 |
+
#: admin/csv-import.php:403
|
523 |
+
msgctxt "admin csv-import"
|
524 |
+
msg
|