From feb2939f621798e51186386b68bfc1471b2e354d Mon Sep 17 00:00:00 2001 From: Remco Tolsma Date: Wed, 30 Apr 2014 09:28:46 +0200 Subject: [PATCH] Added version 1.8. --- change_log.txt | 250 ++ data.php | 249 ++ images/active0.png | Bin 0 -> 666 bytes images/active1.png | Bin 0 -> 727 bytes images/add.png | Bin 0 -> 3448 bytes images/gravity-title-icon-32.png | Bin 0 -> 775 bytes images/loading.gif | Bin 0 -> 1849 bytes images/paypal_wordpress_icon_32.png | Bin 0 -> 808 bytes images/remove.png | Bin 0 -> 3401 bytes images/tick.png | Bin 0 -> 537 bytes images/user-registration-icon-32.png | Bin 0 -> 840 bytes includes/activate.php | 96 + includes/pending_activations.php | 318 ++ includes/signups.php | 245 ++ js/jquery.json-1.3.js | 160 + languages/gravityformsuserregistration.pot | 461 +++ plugin-upgrade.php | 116 + userregistration.php | 3924 ++++++++++++++++++++ 18 files changed, 5819 insertions(+) create mode 100644 change_log.txt create mode 100644 data.php create mode 100644 images/active0.png create mode 100644 images/active1.png create mode 100644 images/add.png create mode 100644 images/gravity-title-icon-32.png create mode 100644 images/loading.gif create mode 100644 images/paypal_wordpress_icon_32.png create mode 100644 images/remove.png create mode 100644 images/tick.png create mode 100644 images/user-registration-icon-32.png create mode 100644 includes/activate.php create mode 100644 includes/pending_activations.php create mode 100644 includes/signups.php create mode 100644 js/jquery.json-1.3.js create mode 100644 languages/gravityformsuserregistration.pot create mode 100644 plugin-upgrade.php create mode 100644 userregistration.php diff --git a/change_log.txt b/change_log.txt new file mode 100644 index 0000000..5edec9c --- /dev/null +++ b/change_log.txt @@ -0,0 +1,250 @@ +----------------------------------------------------------- +Version 1.8 + - Added more debug statements for logging. + - Added logging support and some initial debug statements. + - Updated two strings in activate.php to match their equivalents in wp-activate.php (as of WP 1.8.1). + - Updated signup activation to check if email address is already in use and return a message indicating such. + - Updated all places where RGUserUpgrade class was manually included to use new GFUser::include_upgrade_library() method. + - Fixed notice with missing variable $set_post_author. + - Fixed issue on single site installs where activation email title and from name defaulted to "WordPress". + - Fixed issue on Update form where pre-population didn't always work when a value was set to zero. + - Fixed issue where RGUserUpgrade class was called but not included. + - Fixed issue where single column list fields were not updating correctly on Update feeds. + - Fixed issue where deprecated functions were used in activation process. + - Fixed issue in Update feed on multi-site where email address said to already be used. + +----------------------------------------------------------- +Version 1.7 + - Fixed issue with invalid site domain and path when creating a new site + - Fixed issue with email activation link displaying errors when mapping BBPress fields + - Fixed issue where $base global variable in wp-config.php may not have the trailing slash, causing the site url created to be bad + - Fixed bug where PayPal integration caused user to be registered regardless of being set to manual/email activation + +----------------------------------------------------------- +Version 1.6 + - Updated automatic upgrade so that it caches remote requests for 12 hours (even on plugin's page) + - Updated multisite username and email validation to only apply if the correct page is being validated + - Updated to allow mapping to POST fields for Update User feed + - Fixed issue with form action on activate.php when invalid activation key provided + - Fixed issue with display name not being set correctly on an create feed + - Fixed issue were BP on single site installs was overwriting standard user meta fields (ie first name, last name, nicename) + - Fixed issue where email validation allowed update feeds to use already used email addresses + - Added better support for file uploads on forms with update feeds + - Fixed issue where multisite validation on Update feeds generated error when using existing email + +----------------------------------------------------------- +Version 1.5 + - Added support for custom registration page for multi-site installs + - Fixed link location for drop down on Pending Activations page which takes user to view All pending or form-specific pending + - Fixed issue where All pending activations was returning no records + - Fixed issue where usernames with spaces were not displaying in pending activation table + - Added "back to list" link on successful activation on Pending Activations page + - Updated Pending Activations table to only show form column when viewing All Pending Activations + - Updated UI to remove tabs + - Fixed issue where update_user() function was not correctly saving the user's email + - Fixed errors when populating an update fields with values containing single quotes + - Added support for specifying user activation type (manual, by email) + - Updated roles drop down on feed page to order by a custom sort (subscriber first) + - Fixed issue when updating user's website meta on an update feed + - Fixed issue with mapping category fields to BuddyPress + - Fixed error on update feed form when Buddy Press is uninstalled + - Fixed issue with checkboxes not being saved correctly when unchecked from an update feed + - Fixed issue with date fields not being formatted correctly when populating fields in an update feed + - Fixed issue with plugin-upgrade.php where failed remote response generated several notices + - Added support for saving processed config in entry meta and retrieving this from get_active_config() function + - Fixed issue where multiple file upload fields were not be populated correctly (powered by update feed) + - BP functions bound to gform_user_registered were not being bound in the admin as the gform_user_registered hook was not previously fired in the admin (now fires when manually activating a pending activation) + - Fixed issue where "wp_" prefix was being used instead of "$wpdb->prefix" Busted! + - refactored form population for update feeds + - added support for list fields for update feeds + - fixed issue with date field population for update feeds + - Fixed issue with hardcoded table prefix + - Fixed issue with AJAX call when admin is configured to force SSL + - Fixed issue where Gravity Forms was being required and failing to find plugin + - Fixed issue where values being populated back into form for update feeds were not escaping single quotes which caused errors + - Fixed issue where unescaped single quotes were causing issues on feed editor + - Fixed issue where custom meta fields with 0 as a value weren't saving to the database + - Fixed notices when form inputs array doesn't exist which caused AJAX spinner to remain and no form fields were displayed + - fixed compatability issue with BP 1.6 where BP profile function is no longer available + - added "gform_disable_registration" hook to allow add-ons to prevent User Registration from registering/updating a user + - fixed issue where using wp_get_current_user() function was failing to update users when wait for payment option was checked + - fixed issue where "Pending Activations" link displayed in feed actions for Update feeds + - fixed issue where "Send Email?" option was displaying for Update feeds + - fixed issue where "Preserve current role" option was not preserving user's role for new feeds + - fixed issue were active status was not taken into account when retrieving update feed + - Fixed issue where new feed options were not displaying immediately + - Added support for displaying all user meta keys in feed meta key drop downs + - Fixed UI to read "Action" instead of "Feed Type" + - Added pending activation link to entry detail page + - Added support for multiple feeds per form + - Added support for user activation on a per feed basis + - Added support for "update" feed types + - Added new conditional logic options (greater than, less than, contains starts with, ends with) and support for other conditional fields + - Fixed notices + +----------------------------------------------------------- +Version 1.4 + - Fixed typo + - Fixed issue where users were not visible in the BP member directory + - Added support for displaying user registration notice in activity feed + +----------------------------------------------------------- +Version 1.3 + - Fixed issue when Authorize.net and PayPal feeds were configured on the same form. The PayPal feed was being used sometimes even though the PayPal condition wasn't met + - Fixed issue where inactive feeds were still being processed + - Added several additional parameters to the "gform_username" hook + - Fixed issue where translation files were only being loaded for admin + - Fixed several notices with BuddyPress integration + - Updated function for adding user properties to prevent removal of password + - Added "gform_site_created" hook which triggers after a site has been created + Documentation: http://www.gravityhelp.com/documentation/page/Gform_site_created + - Updated functionality to add website user property correctly + - Updated PayPal integration to support multiple PayPal feeds with the same form + - Fixed notices on the PayPal Transaction Settings for the User Registration section + - Fixed issue where RG_CURRENT_PAGE constant was not available when GF is deactivated + - Added option to feed to allow user to specify the display name of the created user + - Updated code in various places to be cleaner and more effecient + - Added option to select role of new user on new site + - Added option to select role of new user on existing site + - Updated the "Custom Registration Page" functionality to also override BP Register page + - Fixed several PHP notices + - Fixed issue where validation was being processed regardless of a registration condition + - Fixed issue where $entry object was not being passed when checking if registration condition was met + - Fixed issue where GF was calling "gform_post_submission" hook prior to add-on tying function to it + +----------------------------------------------------------- +Version 1.2.11 + - Fixed issue where password was not included on New Site Creation email. + +----------------------------------------------------------- +Version 1.2.10 + - Updated registration_met() function to retrieve submitted value from the lead (rather than $_POST) to be compatible with PayPal Add-on + +----------------------------------------------------------- +Version 1.2.9 + - Fixed issue where empty array values for checkboxes and multiselect fields were being displayed as part of the BP profile data + +----------------------------------------------------------- +Version 1.2.8 + - Fixed issue where erroneous fields with empty inputs array were not displaying in feed fields drop down + +----------------------------------------------------------- +Version 1.2.7 + - Updated custom_registration_page() function to no longer user parse_url() php function + +----------------------------------------------------------- +Version 1.2.6.3 + - Users are not created if entry is marked as spam + - Marking an entry as not spam will create the user + +----------------------------------------------------------- +Version 1.2.6.2 + - Updated how the BuddyPress profile data table name is retrieved + - Updated custom_registration_page() function to parse more complex URLs + +----------------------------------------------------------- +Version 1.2.6.1 + - Updated "Custom Registration Page" functionality; when activated, accessing WP's default registration page will redirect user to specified page + +----------------------------------------------------------- +Version 1.2.6 + - Updated all localization strings to ensure same domain + - Recreated localization POT file + - Updated validation to validate regardless if the registration condition is met + +----------------------------------------------------------- +Version 1.2.5 + - Added cleanup routine to make sure user meta values are not stored as arrays + +----------------------------------------------------------- +Version 1.2.4 + - Added new filter "gform_username" to dynamically assign a username + + add_filter('gform_username', 'auto_username'); + function auto_username($username){ + $username = rgpost('input_2_3') . rgpost('input_2_6'); + return $username; + } + +----------------------------------------------------------- +Version 1.2.3 + - Escaped javascript localization strings + +----------------------------------------------------------- +Version 1.2.2 + - Add new option/functionality to override WP's default registration page with a custom page + - Require BP file in get_buddypress_fields() for users who have BP active but not setup + +----------------------------------------------------------- +Version 1.2.1 + - Updated 'Email Address' field dropdown to also pull custom fields that are set to the Email input type + - Updated is_root_site() function to more reliably determine if the current blog is the root site's blog + - Fixed several notices on User Registration multisite options + +----------------------------------------------------------- +Version 1.2 + - Fixed issue with localization + - Updated UI to support longer translation verbiage + +----------------------------------------------------------- +Version 1.1 + - Fixed issue where all User Registration options were displaying for PayPal Feeds even when no User Registration Feed existed for the selected form + - Fixed issue where User Registration options were not available on a PayPal Feed until after saving the PayPal Feed was saved. + - Feed password field now defaults to a form password field (if available) + +----------------------------------------------------------- +Version 1.0 + - Updated version to 1.0 + +----------------------------------------------------------- +Version 1.0.beta5.3 + - Updated reference to "gforms_paypal_save_config" to use the renamed hook: "gform_paypal_save_config" + - Localized add-on + - Added gravityformsuserregistration.pot file + +----------------------------------------------------------- +Version 1.0.beta5.2 + - Added hook to allow User Registration validation messages to be updated + Example: + add_filter("gform_user_registration_validation_message", "update_validation_msgs", 10, 2); + + function update_validation_msgs($message, $form){ + + if($message == 'This username is already registered') + $message = 'We\'re sorry, this username is already registered. Try submitting with a different username.'; + + return $message; + } + +----------------------------------------------------------- +Version 1.0.beta5.1 + - Updated gf_create_user() code to abort user registration if username already exists; beneficial to prevent existing user data being overwritten if username validation is overriden + +----------------------------------------------------------- +Version 1.0.beta5 + - Added support for all BP field types + - Rewrote function to better retrieve values from the $_POST and $entry object + +----------------------------------------------------------- +Version 1.0.beta4 + - fixed validation issue for multi-page forms where the site address MU registration field was being validated regardless of current page + - fixed "Cancel" button on Edit page to return the user to the List page + - update multisite registration validation to check if site name (domain) already exists + +----------------------------------------------------------- +Version 1.0.beta3.2 + - fixed IE issue where selecting a form on the PayPal addon was generating an error when no User Registration feeds existed + +----------------------------------------------------------- +Version 1.0.beta3 + - added support for creating MultiSite with user registration + - fixed issue where MultiSite was failing to return validation error for spaces in domain name + - disabled MultiSite options on User Resgistration feed view for child sites + +----------------------------------------------------------- +Version 1.0.beta2 + +----------------------------------------------------------- +Version 1.0.beta1 + - updated database name to be consistent with other Gravity Form Add-Ons + - updated permission required to view User Registration menu \ No newline at end of file diff --git a/data.php b/data.php new file mode 100644 index 0000000..cb725b0 --- /dev/null +++ b/data.php @@ -0,0 +1,249 @@ +charset) ) + $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; + if ( ! empty($wpdb->collate) ) + $charset_collate .= " COLLATE $wpdb->collate"; + + require_once(ABSPATH . '/wp-admin/includes/upgrade.php'); + + $sql = "CREATE TABLE $table_name ( + id mediumint(8) unsigned not null auto_increment, + form_id mediumint(8) unsigned not null, + is_active tinyint(1) not null default 1, + meta longtext, + PRIMARY KEY (id), + KEY form_id (form_id) + )$charset_collate;"; + + dbDelta($sql); + + } + + public static function get_user_registration_table_name(){ + global $wpdb; + return $wpdb->prefix . "rg_userregistration"; + } + + public static function get_feeds($form_id = false, $is_active = false){ + global $wpdb; + + $table_name = self::get_user_registration_table_name(); + $form_table_name = RGFormsModel::get_form_table_name(); + $where = 'WHERE 1 = 1'; + + if($form_id) + $where .= " AND s.form_id = $form_id"; + + if($is_active) + $where .= " AND s.is_active = $is_active"; + + $sql = "SELECT s.id, s.is_active, s.form_id, s.meta, f.title as form_title + FROM $table_name s + INNER JOIN $form_table_name f ON s.form_id = f.id + $where"; + + $results = $wpdb->get_results($sql, ARRAY_A); + + $count = sizeof($results); + for($i = 0; $i < $count; $i++){ + $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); + } + + return $results; + } + + public static function delete_feed($id){ + global $wpdb; + $table_name = self::get_user_registration_table_name(); + $wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE id=%s", $id)); + } + + public static function get_feed_by_form($form_id, $only_active = false){ + global $wpdb; + $table_name = self::get_user_registration_table_name(); + $active_clause = $only_active ? " AND is_active=1" : ""; + $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE form_id=%d $active_clause", $form_id); + $results = $wpdb->get_results($sql, ARRAY_A); + if(empty($results)) + return array(); + + // deserializing meta + $count = sizeof($results); + for($i=0; $i<$count; $i++){ + $results[$i]["meta"] = maybe_unserialize($results[$i]["meta"]); + } + + return $results; + } + + /** + * Provides a more accurately named function for getting feeds by form. + * + * @param mixed $form_id + * @param mixed $only_active + */ + public static function get_feeds_by_form($form_id, $only_active = false) { + return self::get_feed_by_form($form_id, $only_active); + } + + public static function get_feed($id){ + global $wpdb; + $table_name = self::get_user_registration_table_name(); + $sql = $wpdb->prepare("SELECT id, form_id, is_active, meta FROM $table_name WHERE id=%d", $id); + $results = $wpdb->get_results($sql, ARRAY_A); + if(empty($results)) + return array(); + + $result = $results[0]; + $result["meta"] = maybe_unserialize($result["meta"]); + return $result; + } + + public static function get_update_feed($form_id, $is_active = true) { + + $feeds = self::get_feeds($form_id, $is_active); + + foreach($feeds as $feed) { + if(rgars($feed, 'meta/feed_type') == 'update') + return $feed; + } + + return false; + } + + public static function update_feed($id, $form_id, $is_active, $setting){ + global $wpdb; + $table_name = self::get_user_registration_table_name(); + $setting = maybe_serialize($setting); + if($id == 0){ + //insert + $wpdb->insert($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("%d", "%d", "%s")); + $id = $wpdb->get_var("SELECT LAST_INSERT_ID()"); + } + else{ + //update + $wpdb->update($table_name, array("form_id" => $form_id, "is_active"=> $is_active, "meta" => $setting), array("id" => $id), array("%d", "%d", "%s"), array("%d")); + } + + return $id; + } + + public static function drop_tables(){ + global $wpdb; + $wpdb->query("DROP TABLE IF EXISTS " . self::get_user_registration_table_name()); + } + + /** + * Forms can have an unlimited number of feeds now. + * + * @param mixed $active_form + */ + + public static function get_available_forms($feed_type, $current_feed = false){ + + $forms = RGFormsModel::get_forms(); + $feeds = self::get_feeds(); + $available_forms = array(); + + // forms can have multiple "create" feeds + // forms can have only a single "update" feed + // any given form can only have one type of feed, a form with a "create" feed can not have an "update" feed and vice versa + $not_type = $feed_type == 'update' ? 'create' : 'update'; + + foreach($forms as $form) { + + // if form already has an update feed, limit to one per form + if($feed_type == 'update' && self::has_feed_type('update', $form, $feeds, $current_feed)) + continue; + + // filter out all feeds of opposing feed type + if(self::has_feed_type($not_type, $form, $feeds, $current_feed)) + continue; + + $available_forms[] = $form; + + } + + return $available_forms; + } + + public static function has_feed_type($feed_type, $form, $feeds, $current_feed = false) { + foreach($feeds as $feed) { + + // skip current feed as it may be changing feed type + if($current_feed && $feed['id'] == $current_feed) + continue; + + // if there is no feed type specified, default to "create" + if(!rgars($feed, 'meta/feed_type')) + $feed['meta']['feed_type'] = 'create'; + + if($form->id == $feed['form_id'] && rgars($feed, 'meta/feed_type') == $feed_type) + return true; + } + return false; + } + + public static function get_user_by_entry_id($entry_id) { + global $wpdb; + + if (!$user_id = $wpdb->get_var($wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'entry_id' AND meta_value = %d LIMIT 1", $entry_id ))) + return false; + + $user = new WP_User($user_id); + + return $user; + + } + + public static function insert_buddypress_data($bp_rows) { + global $wpdb, $bp; + require_once(WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-functions.php'); + + $table = $bp->profile->table_name_data; + + foreach($bp_rows as $bp_row) { + $success = xprofile_set_field_data($bp_row['field_id'], $bp_row['user_id'], $bp_row['value']); + } + + } + + public static function remove_password($form_id, $entry_id, $field_id){ + global $wpdb; + $table = $wpdb->prefix . 'rg_lead_detail'; + $wpdb->query("DELETE FROM $table WHERE lead_id = $entry_id AND form_id = $form_id AND CAST(field_number as DECIMAL(4,2)) = $field_id"); + } + + public static function update_site_meta($site_id, $key, $value){ + global $wpdb; + + $wpdb->show_errors(); + + $meta_id = $wpdb->get_results("SELECT meta_id FROM $wpdb->sitemeta WHERE site_id = '$site_id' AND meta_key = '$key'"); + + if(!empty($meta_id)) { + $meta_id = $meta_id[0]->meta_id; + $result = $wpdb->query("UPDATE $wpdb->sitemeta SET meta_value = '$value' WHERE meta_id = '{$meta_id}'"); + } else { + $result = $wpdb->query("INSERT INTO $wpdb->sitemeta (site_id, meta_key, meta_value) VALUES ('$site_id', '$key', '$value')"); + } + + return $result; + } + + public static function get_site_by_entry_id($entry_id) { + global $wpdb; + + $site_id = $wpdb->get_var("SELECT site_id FROM $wpdb->sitemeta WHERE meta_key = 'entry_id' AND meta_value = '$entry_id'"); + + return $site_id; + } + +} +?> diff --git a/images/active0.png b/images/active0.png new file mode 100644 index 0000000000000000000000000000000000000000..840c3ceedc85ac8f294e3addde2df03db57043df GIT binary patch literal 666 zcmV;L0%iS)P){ZM0bu?5#u6m=Lf@nI%;|g&}FvrM3)Mh%urjf>|uYfR)vX2%@6v|DQQGJPEQ} zW#Ibmdoy$9%$ZRtm&RV9 zgPbv&@3~w~EdW5XR;xYMXf%%kfq0 zYXQKQpEox*#5-_I#=)4BqqK&YPNxGAe>0PX7$b}LuGMNS0fKp-R!0m3_W69&?RKfz zZ0o13S}~xHLL&e1sigZD}%0L@p$}wI-UN;oB52L z7fj#HRWO|%$NgYNpOVSs)xXOnrBW&SANwP~06VwA0N_88WdHyG07*qoM6N<$f~PMr A(*OVf literal 0 HcmV?d00001 diff --git a/images/active1.png b/images/active1.png new file mode 100644 index 0000000000000000000000000000000000000000..003e0bd781e8de01cd2e62c411ee5af8261212a1 GIT binary patch literal 727 zcmV;|0x127P)R0my%7gDN4{~)}oszVybo}7D4K;sOZ+YxXeGexM&DLO+w~* z@SZ0>RB`8npa0&!_ndp~xi8Z8_BQ=vY4m#iqEe}x!C^ceH`?uXd^8%B|4vj5heHYk z0+SC12L~$*UXdh8I~WWACWS&lMx$}eBE#KbYJPqm zB*%0*-F?IqNaD)Ns49ce_tAChb&!7MD|F`ioFL&=L3|EaLBJA^BY&Zw0USs5ZnrA{ctCU%yuSQdd;@{WWFnpj&Q2Bj;0;PjsQm5gcQTu` zwEE`s1pMOK?nD_L_CWZQP8H}^s65eRFR4RdRz%3sN0^WS6 z)oR3dKqNg~`Xs7QxnO^fx&LK zn+k;jWipu&gKvs4;>YLn?Xo$y)9LgW@?0(#O-)US3xsQIu~=w&dYW>%9L3{tkUa{A z!!bc1%L@jBcUZxVL?Y4L-{0pJ>TISN{{bo%iD$L*!>5WcmV^f3UcKY3We@P zqtUl~GcRy(k>xwN3a0ae^WL+fhmlBRSI!4kT3cJA|5?8T7y!o+!BSg{F!}%h002ov JPDHLkV1i0VQa=Cy literal 0 HcmV?d00001 diff --git a/images/add.png b/images/add.png new file mode 100644 index 0000000000000000000000000000000000000000..227426e8a911d892fb507c1d059f1a8704935765 GIT binary patch literal 3448 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 FV1jA1SP1|C literal 0 HcmV?d00001 diff --git a/images/loading.gif b/images/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..d42f72c723644bbf8cf8d6e1b7ff0bea7ddd305a GIT binary patch literal 1849 zcma*odr%wI9tZGc_iT2vk7P+x3@LU(2yGIQCcHvgYTblq0THkTesI znR7n#{hi;OjP2?A&1ME-pkE;9;lqaz1T8KudOV)_`T6wp^p=(uf2Fv%SSFK=kB@u3 zUZGGpJUk2l(CKv5)z$vpzrP~?FHUK&nD<(COPZ{Et0m?db93z;^X^U7=d1QWkq-bw z_z#PGNam*Pcq+w^mln54i-h<~s=yrqB!o6eBrwd4{B{&hHR9I{{bQLC?)mG!al!d3 z<_YADRELlGj+H!fNocrRe7`?$gk5?^y3^@6pC85jwesu>G6*{Wrto)mL5D?z)j-L++&!SNH!MDuhyZ1*)jGIdEgHH>qdP6}DTp>kJ!bZd!oke!Q0J5vRHHSl&=?=ft+HzcfBB?ZKg#rgtngf(C zDL)0I;%QR6Z_49x&crpS#vVCUpEoP)gxevZsOEytw5Vq|*bf39%i#K5VVMGzL^=13 zR-}G|UaU(m68*HWc{(R=BrQG$CK$N`HcDv@S=IAWm(o~Np>ZF8X|_V%3_!1*u`vm}?t+-#K2Qs= zlXouK&f(YJG|lD7kLqye?NcYji#s*HOSm|xQ~{R)Ao3VZxwQ7l4$VQO;kkhWM?7Tq zV7I5-(5BO!(yinIf+@AjEfNKCk>b~u*83@)>qu(a3nA*y_1a7za7?y8mYaN9Z=br4iilUPLeBE8>z7SjUY!R@qdmA$~nkLiZ z9qy{OsKf4~y1^q+D*!YY&=vr^tMUUJQrx*Do>dYDlPO!l`DoZR5vApf95=i4Lz;yXc(}m~6Zh#oS@fHF;-MHT+t;8_YoNLuk zSUE;16g_GThjJ{n2e=qnXWb70jIOhk#;lMy!K4=hr0tBKfB(rz4e z+1U)aJZHl#TYU{%(($JI!F!<+%Jp+Jdk!#Y(|CzO!nka;h@9x_wBI_{i{tgbHY(SI zVOYV2N)E%tOc-CGkW(0fy>Or+s~>c2t0?1P8+jRZNqDzxRf7dRy(%%W_#a<6{e3caEW8DdD|KsdZBw z(K6nRmw&K{D1uvtp&1a;%;nPiAvOlI0*Zq9*kdsS7JEd^O*1FLwTe{>9&A}oMlrlF z`pQPbaQ2zQZ_j_#qk8qy|9IetJFQG!>l{9_AvsafGtVRnQr)xR?bImN4qo-#?gP`}S)0UYaWY9t`6HQwY4B_($TWNu`l?!*nIBy_|7=pQc9cnFU zs%%oO^oje|8ddh7^1-E9_|T~KBxydL{KcW06CqFQ?Ym3~cb^|wPx?lUyCBD|_nRZU zsA}@ctKd0_^(q#G?{G;+$w=8-md|N>W6e5@3AT19SLRCCSyG z=oV%uMus5!Ry9PhrZMnpmb0lXJuACSOl2|krLXzwsrVsNe(8N);u`z?E#W-RKNi9E z;z;dGgCSKfqEhya^?xWt|DBmvWexQ%SfTtu(C0Mdv9@(g3WttPh3GsE1Niv~Ituk; zXltbvX7Jn^Z4>QMtd0~JELrW+CaT^$N~khm@~tceYLLGjk=3uK@XnOQ1!btG^Pus9 zYDnDM@%;wTR-(h+ec@l>g6c`Cs7=j$FkqTfajDLuzmAAh_qHK0!$~G+eL?P46^V2( gTVr?dnQ{(H{Ie1a9NS3OKPMyDfF?Qc5iPGj047fkWdHyG literal 0 HcmV?d00001 diff --git a/images/paypal_wordpress_icon_32.png b/images/paypal_wordpress_icon_32.png new file mode 100644 index 0000000000000000000000000000000000000000..884529690e490e09f4451eb2475c37edcd67bfa8 GIT binary patch literal 808 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 S>>_ah0000 + + + +
+ + +

+
+

+ +
+

+

+ +

+
+ + get_error_code() || 'blog_taken' == $result->get_error_code() ) { + $signup = $result->get_error_data(); + ?> +

+ '; + if ( $signup->domain . $signup->path == '' ) { + printf( __('Your account has been activated. You may now log in to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can reset your password.'), network_site_url( 'wp-login.php', 'login' ), $signup->user_login, $signup->user_email, network_site_url( 'wp-login.php?action=lostpassword', 'login' ) ); + } else { + printf( __('Your site at %2$s is active. You may now log in to your site using your chosen username of “%3$s”. Please check your email inbox at %4$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can reset your password.'), 'http://' . $signup->domain, $signup->domain, $signup->user_login, $signup->user_email, network_site_url( 'wp-login.php?action=lostpassword' ) ); + } + echo '

'; + } else { + ?> +

+ '.$result->get_error_message().'

'; + } + } else { + extract($result); + $url = is_multisite() ? get_blogaddress_by_id( (int) $blog_id) : home_url('', 'http'); + $user = new WP_User( (int) $user_id); + ?> +

+ +
+

user_login ?>

+

+
+ + +

View your site or Log in'), $url, $url . 'wp-login.php' ); ?>

+ +

Log in or go back to the homepage.' ), network_site_url('wp-login.php', 'login'), network_home_url() ); ?>

+ +
+ + \ No newline at end of file diff --git a/includes/pending_activations.php b/includes/pending_activations.php new file mode 100644 index 0000000..6fe2bf6 --- /dev/null +++ b/includes/pending_activations.php @@ -0,0 +1,318 @@ + + + + +
+ + + +

+

+ id ) . '">' . $form->title . '"'; + printf( __('Pending Activations for %s'), $form_link); + } ?> +

+ +
+ + + + +
+ + +

+ +

+ + +
+ + prepare_items(); + $table->display(); + ?> + + + + + + + +
+ +
+ + + + 'DESC', + 'order_by' => 'registered', + 'page' => 1, + 'per_page' => 10, + 'get_total' => false, + 'lead_id' => false + ))); + + if(!is_multisite()) { + require_once(GFUser::get_base_path() . '/includes/signups.php'); + GFUserSignups::prep_signups_functionality(); + } + + $where = array(); + + if($form_id) + $where[] = $wpdb->prepare("l.form_id = %d", $form_id); + + if($lead_id) + $where[] = $wpdb->prepare("l.id = %d", $lead_id); + + $where[] = "s.active = 0"; + $where = 'WHERE ' . implode(' AND ', $where); + + $order = $wpdb->prepare("ORDER BY %s %s", $order_by, $order); + $offset = ($page * $per_page) - $per_page; + $limit_offset = $get_total ? '' : "LIMIT $per_page OFFSET $offset"; + $method = $get_total ? 'get_var' : 'get_results'; + + if($form_id) { + + $select = $get_total ? 'SELECT count(s.activation_key)' : 'SELECT s.*' ; + $sql = " + $select FROM {$wpdb->prefix}rg_lead_meta lm + INNER JOIN {$wpdb->signups} s ON s.activation_key = lm.meta_value AND lm.meta_key = 'activation_key' + INNER JOIN {$wpdb->prefix}rg_lead l ON l.id = lm.lead_id + $where + $order + $limit_offset"; + $results = $wpdb->$method($sql); + + } else { + + $select = $get_total ? 'SELECT count(s.activation_key)' : 'SELECT s.*' ; + $results = $wpdb->$method(" + $select FROM $wpdb->signups s + $where + $order + $limit_offset" + ); + + } + + return $results; + } + + private static function process_bulk_action() { + + } + + public static function handle_submission() { + + if(!wp_verify_nonce(rgpost('action_nonce'), 'action') && !check_admin_referer('action_nonce', 'action_nonce')) + die('You have failed...'); + + require_once(GFUser::get_base_path() . '/includes/signups.php'); + GFUserSignups::prep_signups_functionality(); + + self::$errors = ''; + self::$message = ''; + + $action = rgpost('single_action'); + $action = !$action ? rgpost('action') != -1 ? rgpost('action') : rgpost('action2') : $action; + + $items = rgpost('item') ? array(rgpost('item')) : rgpost('items'); + + foreach($items as $key) { + + switch($action) { + case 'delete': + $success = GFUserSignups::delete_signup($key); + if($success) { + self::$message = _n('Item deleted.', 'Items deleted.', count($items), 'graivtyformsuserregistration'); + } else { + self::$errors = _n('There was an issue deleting this item.', 'There was an issue deleting one or more selected items.', count($items), 'graivtyformsuserregistration'); + } + break; + case 'activate': + $userdata = GFUserSignups::activate_signup($key); + if(!is_wp_error($userdata) && rgar($userdata, 'user_id')) { + self::$message = _n('Item activated.', 'Items activated.', count($items), 'graivtyformsuserregistration'); + } else { + self::$errors = _n('There was an issue activating this item', 'There was an issue activating one or more selected items', count($items), 'graivtyformsuserregistration'); + if(is_wp_error($userdata)) { + $errors = reset($userdata->errors); + self::$errors .= ": " . $errors[0]; + } + } + break; + } + + } + + } + +} + +require_once(ABSPATH . '/wp-admin/includes/class-wp-list-table.php'); + +class GFUserPendingActivationsList extends WP_List_Table { + + var $_column_headers; + + function __construct() { + + $this->items = array(); + $this->_column_headers = array( + array( + 'cb' => '', + 'form' => 'Form', + 'user_login' => 'Username', + 'email' => 'Email', + 'date' => 'Sign Up Date', + ), + array(), + array() + ); + + parent::__construct(); + + } + + function prepare_items() { + + $items = array(); + $forms = array(); + $per_page = 10; + $page = rgget('paged') ? rgget('paged') : 1; + $pending_activations = GFUserPendingActiviations::get_pending_activations(rgget('form_id'), array('per_page' => $per_page, 'page' => $page)); + $total_pending = GFUserPendingActiviations::get_pending_activations(rgget('form_id'), array('per_page' => $per_page, 'page' => $page, 'get_total' => true)); + + foreach($pending_activations as $pending_activation) { + $signup_meta = unserialize($pending_activation->meta); + + $lead = RGFormsModel::get_lead(rgar($signup_meta, 'lead_id')); + + //if(!$lead) + //continue; + + $form_id = $lead['form_id']; + $form = rgar($forms, $form_id) ? rgar($forms, $form_id) : RGFormsModel::get_form_meta($form_id); + $forms[$form_id] = $form; + + $item = array(); + $item['form'] = $form['title']; + $item['user_login'] = rgar($signup_meta, 'user_login'); + $item['email'] = rgar($signup_meta, 'email'); + $item['date'] = $lead['date_created']; + + // non-columns + $item['lead_id'] = $lead['id']; + $item['form_id'] = $form_id; + $item['activation_key'] = $pending_activation->activation_key; + + array_push($this->items, $item); + + } + + $this->set_pagination_args(array( + 'total_items' => $total_pending, + 'per_page' => $per_page, + )); + + } + + function column_default($item, $column_name) { + return rgar($item, $column_name); + } + + function column_cb($item) { + return ''; + } + + function column_form($item) { + $str = '' . rgar($item, 'form') . ''; + $str .= ' +
+ + Activate | + + + View Entry | + + + Delete + +
'; + + return $str; + } + + function column_date($item) { + return GFCommon::format_date(rgar($item, 'date'), false); + } + + function get_bulk_actions() { + $actions = array( + 'activate' => __('Activate', 'gravityformsuserregistration'), + 'delete' => __('Delete', 'gravityformsuserregistration') + ); + + return $actions; + } + +} + +?> diff --git a/includes/signups.php b/includes/signups.php new file mode 100644 index 0000000..ac7244b --- /dev/null +++ b/includes/signups.php @@ -0,0 +1,245 @@ +signups ( + domain varchar(200) NOT NULL default '', + path varchar(100) NOT NULL default '', + title longtext NOT NULL, + user_login varchar(60) NOT NULL default '', + user_email varchar(100) NOT NULL default '', + registered datetime NOT NULL default '0000-00-00 00:00:00', + activated datetime NOT NULL default '0000-00-00 00:00:00', + active tinyint(1) NOT NULL default '0', + activation_key varchar(50) NOT NULL default '', + meta longtext, + KEY activation_key (activation_key), + KEY domain (domain) + ) $charset_collate;"; + + // now create table + dbDelta($ms_queries); + } + + /** + * Add signups property to $wpdb object. Used by several MS functions. + */ + private static function add_signups_to_wpdb() { + global $wpdb; + $wpdb->signups = $wpdb->prefix . 'signups'; + } + + public static function prep_signups_functionality() { + + if(!is_multisite()) { + + // require MS functions + require_once(ABSPATH . 'wp-includes/ms-functions.php'); + + // add $wpdb->signups property (accessed in various MS functions) + self::add_signups_to_wpdb(); + + // remove filter which checks for Network setting (not active on non-ms install) + remove_filter('option_users_can_register', 'users_can_register_signup_filter'); + + } + + // signup: update the signup URL to GF's custom activation page + add_filter( 'wpmu_signup_user_notification_email', array( 'GFUserSignups', 'modify_signup_user_notification_message' ), 10, 4 ); + add_filter( 'wpmu_signup_blog_notification_email', array( 'GFUserSignups', 'modify_signup_blog_notification_message' ), 10, 7 ); + + add_filter( 'wpmu_signup_user_notification', array( __class__, 'add_site_name_filter' ) ); + add_filter( 'wpmu_signup_user_notification_subject', array( __class__, 'remove_site_name_filter' ) ); + + // signup: BP cancels default MS signup notification and replaces with its own; hook up to BP's custom notification hook + if( GFUser::is_bp_active() ) { + add_filter('bp_core_activation_signup_user_notification_message', array('GFUserSignups', 'modify_signup_user_notification_message'), 10, 4); + add_filter('bp_core_activation_signup_blog_notification_message', array('GFUserSignups', 'modify_signup_blog_notification_message'), 10, 7); + } + + } + + public static function modify_signup_user_notification_message($message, $user, $user_email, $key) { + + $signup = GFSignup::get( $key ); + + // if no signup or config is set for manual activation, return false preventing signup notification from being sent to user + if( is_wp_error( $signup ) || $signup->get_activation_type() == 'manual' ) + return false; + + $url = add_query_arg(array('page' => 'gf_activation', 'key' => $key), get_site_url() . '/' ); + + // BP replaces URL before passing the message, get the BP activation URL and replace + if( GFUser::is_bp_active() ) { + $activate_url = esc_url(bp_get_activation_page() . "?key=$key"); + $message = str_replace($activate_url, '%s', $message); + } + + return sprintf($message, $url); + } + + public static function modify_signup_blog_notification_message($message, $domain, $path, $title, $user, $user_email, $key) { + + $signup = GFSignup::get( $key ); + + // if no signup or config is set for manual activation, return false preventing signup notification from being sent to user + if( is_wp_error( $signup ) || $signup->get_activation_type() == 'manual' ) + return false; + + $url = add_query_arg(array('page' => 'gf_activation', 'key' => $key), get_site_url()); + + // BP replaces URL before passing the message, get the BP activation URL and replace + if(GFUser::is_bp_active()) { + $activate_url = esc_url(bp_get_activation_page() . "?key=$key"); + $message = str_replace($activate_url, '%s', $message); + } + + return sprintf($message, $url, esc_url("http://{$domain}{$path}"), $key); + } + + public static function add_site_name_filter( $return ) { + add_filter( 'site_option_site_name', array( __class__, 'modify_site_name' ) ); + return $return; + } + + public static function remove_site_name_filter( $return ) { + remove_filter( 'site_option_site_name', array( __class__, 'modify_site_name' ) ); + return $return; + } + + public static function modify_site_name( $site_name ) { + + if( ! $site_name ) + $site_name = get_site_option( 'blogname' ); + + return $site_name; + } + + public static function add_signup_meta($lead_id, $activation_key) { + gform_update_meta($lead_id, 'activation_key', $activation_key); + } + + public static function get_lead_activation_key($lead_id) { + global $wpdb; + return $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}rg_lead_meta WHERE lead_id = %d AND meta_key = 'activation_key'", $lead_id)); + } + + /** + * Activate a signup. + * + */ + public static function activate_signup($key) { + global $wpdb, $current_site; + + $blog_id = is_object($current_site) ? $current_site->id : false; + $signup = GFSignup::get( $key ); + + if( is_wp_error( $signup ) ) + return $signup; + + $user_id = username_exists( $signup->user_login ); + if ($user_id){ + //username already exists, go ahead and mark signup activated and return error message + $signup->set_as_activated(); + return new WP_Error('user_already_exists', __( 'That username is already activated.' ), $signup); + } + if (email_exists($signup->user_email)){ + //email address already exists, return error message + return new WP_Error('email_already_exists', __( 'Sorry, that email address is already used!' ), $signup); + } + + // unbind site creation from gform_user_registered hook, run it manually below + if(is_multisite()) + remove_action( 'gform_user_registered' , array( 'GFUser', 'create_new_multisite' ) ); + + $user_data = GFUser::create_user( $signup->lead, $signup->form, $signup->config); + $user_id = rgar($user_data, 'user_id'); + + if(!$user_id){ + return new WP_Error('create_user', __('Could not create user'), $signup); + } + + $signup->set_as_activated(); + + do_action('gform_activate_user', $user_id, $user_data, $signup->meta); + + if(is_multisite()) { + $ms_options = rgars( $signup->config, 'meta/multisite_options'); + if($ms_options['create_site']) + $blog_id = GFUser::create_new_multisite($user_id, $signup->config, $signup->lead, $user_data['password']); + } + + return array('user_id' => $user_id, 'password' => $user_data['password'], 'blog_id' => $blog_id); + } + + public static function delete_signup($key) { + global $wpdb; + return $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->signups WHERE activation_key = %s", $key)); + } + +} + +/** +* Create a signup object from a signup key. +*/ + +class GFSignup { + + public $meta; + public $lead; + public $form; + public $config; + + private $error; + + function __construct( $signup ) { + + // @alex: not sure this is a good thing to do? + foreach( $signup as $key => $value ) { + $this->$key = $value; + } + + $this->meta = unserialize( $signup->meta ); + $this->lead = RGFormsModel::get_lead( $this->meta['lead_id'] ); + $this->form = RGFormsModel::get_form_meta( $this->lead['form_id'] ); + $this->config = GFUser::get_active_config( $this->form, $this->lead ); + + } + + public static function get( $key ) { + global $wpdb; + + $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) ); + + if(empty($signup)) + return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); + + if($signup->active) + return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); + + return new GFSignup( $signup ); + } + + function get_activation_type() { + return rgars( $this->config, 'meta/user_activation_type' ); + } + + function set_as_activated() { + global $wpdb; + + $now = current_time('mysql', true); + $result = $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $this->activation_key ) ); + + return $result; + } + +} + +?> diff --git a/js/jquery.json-1.3.js b/js/jquery.json-1.3.js new file mode 100644 index 0000000..412e6cd --- /dev/null +++ b/js/jquery.json-1.3.js @@ -0,0 +1,160 @@ +/* + * jQuery JSON Plugin + * version: 1.0 (2008-04-17) + * + * This document is licensed as free software under the terms of the + * MIT License: http://www.opensource.org/licenses/mit-license.php + * + * Brantley Harris technically wrote this plugin, but it is based somewhat + * on the JSON.org website's http://www.json.org/json2.js, which proclaims: + * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that + * I uphold. I really just cleaned it up. + * + * It is also based heavily on MochiKit's serializeJSON, which is + * copywrited 2005 by Bob Ippolito. + */ + +(function($) { + function toIntegersAtLease(n) + // Format integers to have at least two digits. + { + return n < 10 ? '0' + n : n; + } + + Date.prototype.toJSON = function(date) + // Yes, it polutes the Date namespace, but we'll allow it here, as + // it's damned usefull. + { + return this.getUTCFullYear() + '-' + + toIntegersAtLease(this.getUTCMonth()) + '-' + + toIntegersAtLease(this.getUTCDate()); + }; + + var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g; + var meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }; + + $.quoteString = function(string) + // Places quotes around a string, inteligently. + // If the string contains no control characters, no quote characters, and no + // backslash characters, then we can safely slap some quotes around it. + // Otherwise we must also replace the offending characters with safe escape + // sequences. + { + if (escapeable.test(string)) + { + return '"' + string.replace(escapeable, function (a) + { + var c = meta[a]; + if (typeof c === 'string') { + return c; + } + c = a.charCodeAt(); + return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); + }) + '"'; + } + else{ + string = string.replace('\n','\\n'); + } + return '"' + string + '"'; + }; + + $.toJSON = function(o, compact) + { + var type = typeof(o); + + if (type == "undefined") + return "undefined"; + else if (type == "number" || type == "boolean") + return o + ""; + else if (o === null) + return "null"; + + // Is it a string? + if (type == "string") + { + var str = $.quoteString(o); + return str; + } + + // Does it have a .toJSON function? + if (type == "object" && typeof o.toJSON == "function") + return o.toJSON(compact); + + // Is it an array? + if (type != "function" && typeof(o.length) == "number") + { + var ret = []; + for (var i = 0; i < o.length; i++) { + ret.push( $.toJSON(o[i], compact) ); + } + if (compact) + return "[" + ret.join(",") + "]"; + else + return "[" + ret.join(", ") + "]"; + } + + // If it's a function, we have to warn somebody! + if (type == "function") { + throw new TypeError("Unable to convert object of type 'function' to json."); + } + + // It's probably an object, then. + var ret = []; + for (var k in o) { + var name; + type = typeof(k); + + if (type == "number") + name = '"' + k + '"'; + else if (type == "string") + name = $.quoteString(k); + else + continue; //skip non-string or number keys + + var val = $.toJSON(o[k], compact); + if (typeof(val) != "string") { + // skip non-serializable values + continue; + } + + if (compact) + ret.push(name + ":" + val); + else + ret.push(name + ": " + val); + } + return "{" + ret.join(", ") + "}"; + }; + + $.compactJSON = function(o) + { + return $.toJSON(o, true); + }; + + $.evalJSON = function(src) + // Evals JSON that we know to be safe. + { + return eval("(" + src + ")"); + }; + + $.secureEvalJSON = function(src) + // Evals JSON in a way that is *more* secure. + { + var filtered = src; + filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@'); + filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'); + filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); + + if (/^[\],:{}\s]*$/.test(filtered)) + return eval("(" + src + ")"); + else + throw new SyntaxError("Error parsing JSON, source is not valid."); + }; +})(jQuery); diff --git a/languages/gravityformsuserregistration.pot b/languages/gravityformsuserregistration.pot new file mode 100644 index 0000000..7c44d07 --- /dev/null +++ b/languages/gravityformsuserregistration.pot @@ -0,0 +1,461 @@ +msgid "" +msgstr "" +"Project-Id-Version: Gravity Forms User Registration\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2011-07-16 05:47-0500\n" +"PO-Revision-Date: 2011-07-16 05:53-0500\n" +"Last-Translator: David Smith \n" +"Language-Team: Rocket Genius \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-KeywordsList: _;gettext;gettext_noop;_e;__\n" +"X-Poedit-Basepath: .\n" +"X-Poedit-SearchPath-0: C:\\xampp\\htdocs\\wp-content\\plugins\\gravityformsuserregistration\n" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/plugin-upgrade.php:56 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:166 +#, php-format +msgid "View version %s Details" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/plugin-upgrade.php:75 +#, php-format +msgid "Oops!! Something went wrong.%sPlease try again or %scontact us%s." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:159 +msgid "Gravity Forms " +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:166 +msgid "There is a new version of Gravity Forms User Registration Add-On available." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:167 +#, php-format +msgid "%sRegister%s your copy of Gravity Forms to receive access to automatic upgrades and support. Need a license key? %sPurchase one now%s." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:207 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:233 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:285 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:522 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1989 +msgid "User Registration" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:223 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:625 +msgid "Gravity Form" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:223 +msgid "Select the Gravity Form you would like to use to register users for your WordPress website." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:224 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:660 +msgid "Username" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:224 +msgid "Select the form field that should be used for the user's username." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:225 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:665 +msgid "First Name" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:225 +msgid "Select the form field that should be used for the user's first name." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:226 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:670 +msgid "Last Name" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:226 +msgid "Select the form field that should be used for the user's last name." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:227 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:675 +msgid "Email Address" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:227 +msgid "Select the form field that should be used for the user's email address." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:228 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:680 +msgid "Password" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:228 +msgid "Select the form field that should be used for the user's password." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:229 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:689 +msgid "Role" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:229 +msgid "Select the role the user should be assigned." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:230 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:716 +msgid "Send Email?" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:230 +msgid "Specify whether to send the password to the new user by email. Enabled by default." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:231 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:723 +msgid "Set As Post Author" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:231 +msgid "When a form submission creates a post and registers a user, set the new user as the post author. Enabled by default." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:232 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:730 +msgid "Registration Condition" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:232 +msgid "When the registration condition is enabled, form submissions will only register the user when the condition is met. When disabled the user will not be registered." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:233 +msgid "The selected form also has a User Registration feed. These options allow you to specify how you would like the PayPal and User Registration Add-ons to work together." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:234 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1436 +msgid "Create Site" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:234 +msgid "When WordPress Multisite is enabled, checking this option will enable the creation of a new site on the network when a new user registers." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:235 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1444 +msgid "Site Address" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:235 +msgid "Select the form field that should be used for the site address." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:236 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1449 +msgid "Site Title" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:236 +msgid "Select the form field that should be used for the site title." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:256 +#, php-format +msgid "User Registration Add-On requires Gravity Forms %s. Upgrade automatically on the %sPlugin page%s." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:268 +msgid "Feed deleted." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:279 +msgid "Feeds deleted." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:286 +msgid "User Registration Forms" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:287 +msgid "Add New" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:297 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:299 +msgid "Bulk action" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:300 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:342 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2028 +msgid "Delete" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:303 +msgid "Apply" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:303 +msgid "Delete selected feeds? " +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:303 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:342 +msgid "\\'Cancel\\' to stop, \\'OK\\' to delete." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:312 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:320 +msgid "Form" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:333 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:380 +msgid "Active" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:333 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:376 +msgid "Inactive" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:335 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:338 +msgid "Edit" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:342 +msgid "Delete this feed? " +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:354 +#, php-format +msgid "You don't have any User Registration feeds configured. Let's go %screate one%s!" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:391 +msgid "Ajax error while updating feed" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:412 +#, php-format +msgid "Gravity Forms User Registration Add-On has been successfully uninstalled. It can be re-activated from the %splugins page%s." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:433 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:523 +msgid "User Registration Settings" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:437 +msgid "Custom Registration Page" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:440 +msgid "Enable Custom Registration Page" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:459 +msgid "Save Settings" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:467 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:470 +msgid "Uninstall User Registration Add-On" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:468 +msgid "Warning! This operation deletes ALL User Registration Feeds." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:470 +msgid "Warning! ALL User Registration Feeds will be deleted. This cannot be undone. \\'OK\\' to delete, \\'Cancel\\' to stop" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:581 +#, php-format +msgid "Feed Updated. %sback to list%s" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:601 +msgid "Auto Generate Password" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:618 +msgid "Your Registration Feed could not be saved. Please update the errors below and re-save your feed." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:628 +msgid "Select a form" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:648 +msgid "The form selected does not have any Email fields. Please add an Email field to the form and try again." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:660 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:675 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1444 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1449 +msgid "required" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:719 +msgid "Send this password to the new user by email." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:726 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:734 +msgid "Enable" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:739 +msgid "Register the user if " +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:745 +msgid "is" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:746 +msgid "is not" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:753 +msgid "To create a registration condition, your form must have a drop down, checkbox or multiple choice field" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:764 +msgid "Save" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:764 +msgid "Update" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:765 +msgid "Cancel" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:813 +msgid "Ajax error while selecting a form" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:889 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1298 +msgid "add another rule" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:891 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1300 +msgid "remove this rule" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:935 +msgid "Enter Meta Name" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1433 +msgid "Multisite Options" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1438 +msgid "Create new site when a user registers." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1579 +#, php-format +msgid "" +"New site created by %1s\n" +"\n" +"Address: http://%2s\n" +"Name: %3s" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1580 +#, php-format +msgid "[%s] New Site Created" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1778 +msgid "This username is already registered" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1781 +msgid "The username can only contain alphanumeric characters (A-Z, 0-9), underscores, dashes and spaces" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1784 +msgid "The username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1787 +msgid "The username can not be empty" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1793 +msgid "This email address is already registered" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1796 +msgid "The email address can not be empty" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:1800 +msgid "Passwords may not contain the character \"\\\"" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2000 +msgid "Register user only when a payment is received." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2002 +msgid "Register user and create site only when a payment is received." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2010 +msgid "Update user when subscription is cancelled." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2016 +#, php-format +msgid "Set User as %s" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2025 +msgid "Update site when subscription is cancelled." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2028 +msgid "Deactivate" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2030 +#, php-format +msgid "%s site" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2130 +msgid "You don't have adequate permission to uninstall the User Registration Add-On." +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2176 +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2235 +msgid "Full" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2335 +msgid "Register" +msgstr "" + +#: C:\xampp\htdocs\wp-content\plugins\gravityformsuserregistration/userregistration.php:2343 +msgid "Site Admin" +msgstr "" + diff --git a/plugin-upgrade.php b/plugin-upgrade.php new file mode 100644 index 0000000..0edf718 --- /dev/null +++ b/plugin-upgrade.php @@ -0,0 +1,116 @@ +response[$plugin_path])) + $option->response[$plugin_path] = new stdClass(); + + //Empty response means that the key is invalid. Do not queue for upgrade + if(!$version_info["is_valid_key"] || version_compare($version, $version_info["version"], '>=')){ + unset($option->response[$plugin_path]); + } + else{ + $option->response[$plugin_path]->url = $plugin_url; + $option->response[$plugin_path]->slug = $plugin_slug; + $option->response[$plugin_path]->package = str_replace("{KEY}", $key, $version_info["url"]); + $option->response[$plugin_path]->new_version = $version_info["version"]; + $option->response[$plugin_path]->id = "0"; + } + + return $option; + + } + + + public static function display_plugin_message($message, $is_error = false){ + + $style = ''; + + if($is_error) + $style = 'style="background-color: #ffebe8;"'; + + echo '
' . $message . '
'; + } + + public static function display_upgrade_message($plugin_name, $plugin_title, $version, $message, $localization_namespace){ + $upgrade_message = $message .' '. sprintf(__('View version %s Details', $localization_namespace), $version) . '. '; + self::display_plugin_message($upgrade_message); + } + + //Displays current version details on Plugin's page + public static function display_changelog($offering, $key, $version){ + + $body = "key=$key"; + $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body); + $options['headers'] = array( + 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), + 'Content-Length' => strlen($body), + 'User-Agent' => 'WordPress/' . get_bloginfo("version"), + 'Referer' => get_bloginfo("url") + ); + + $raw_response = wp_remote_request(GRAVITY_MANAGER_URL . "/changelog.php?" . self::get_remote_request_params($offering, $key, $version), $options); + + if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code']){ + $page_text = sprintf(__("Oops!! Something went wrong.%sPlease try again or %scontact us%s.", 'gravityformsuser'), "
", "", ""); + } + else{ + $page_text = $raw_response['body']; + if(substr($page_text, 0, 10) != "") + $page_text = ""; + } + echo stripslashes($page_text); + + exit; + } + + public static function get_version_info($offering, $key, $version, $use_cache=true){ + + $version_info = function_exists('get_site_transient') ? get_site_transient("gforms_userregistration_version") : get_transient("gforms_userregistration_version"); + if(!$version_info || !$use_cache){ + + $body = "key=$key"; + $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body); + $options['headers'] = array( + 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), + 'Content-Length' => strlen($body), + 'User-Agent' => 'WordPress/' . get_bloginfo("version"), + 'Referer' => get_bloginfo("url") + ); + $url = GRAVITY_MANAGER_URL . "/version.php?" . self::get_remote_request_params($offering, $key, $version); + $raw_response = wp_remote_request($url, $options); + + if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code']){ + $version_info = -1; + } + else + { + $ary = array_pad(explode("||", $raw_response['body']), 3, null); + $version_info = array("is_valid_key" => $ary[0], "version" => $ary[1], "url" => $ary[2]); + } + self::set_version_info($version_info); + } + return $version_info; + } + + public static function get_remote_request_params($offering, $key, $version){ + global $wpdb; + return sprintf("of=%s&key=%s&v=%s&wp=%s&php=%s&mysql=%s", urlencode($offering), urlencode($key), urlencode($version), urlencode(get_bloginfo("version")), urlencode(phpversion()), urlencode($wpdb->db_version())); + } + +} +?> diff --git a/userregistration.php b/userregistration.php new file mode 100644 index 0000000..6836374 --- /dev/null +++ b/userregistration.php @@ -0,0 +1,3924 @@ +", ""); + RGUserUpgrade::display_plugin_message($message, true); + } + else{ + $version_info = RGUserUpgrade::get_version_info(self::$slug, self::get_key(), self::$version); + + if(!$version_info["is_valid_key"]){ + $new_version = version_compare(self::$version, $version_info["version"], '<') ? __('There is a new version of Gravity Forms User Registration Add-On available.', 'gravityformsuserregistration') .' '. sprintf(__('View version %s Details', 'gravityformsuserregistration'), $version_info["version"]) . '. ' : ''; + $message = $new_version . sprintf(__('%sRegister%s your copy of Gravity Forms to receive access to automatic upgrades and support. Need a license key? %sPurchase one now%s.', 'gravityformsuserregistration'), '', '', '', '') . ''; + RGUserUpgrade::display_plugin_message($message); + } + } + } + + //Displays current version details on Plugin's page + public static function display_changelog() { + + if( $_REQUEST['plugin'] != self::$slug ) + return; + + self::include_upgrade_library(); + RGUserUpgrade::display_changelog( self::$slug, self::get_key(), self::$version ); + + } + + public static function check_update($update_plugins_option){ + self::include_upgrade_library(); + return RGUserUpgrade::check_update( self::$path, self::$slug, self::$url, self::$slug, self::get_key(), self::$version, $update_plugins_option ); + } + + private static function get_key(){ + if(self::is_gravityforms_supported()) + return GFCommon::get_key(); + else + return ""; + } + + public static function include_upgrade_library() { + if( ! class_exists( 'RGUserUpgrade' ) ) + require_once( 'plugin-upgrade.php' ); + } + + //------------------------------------------------------------------------ + + // Creates User Registration left nav menu under Forms + public static function create_menu($menus){ + + // Adding submenu if user has access + $permission = self::has_access("gravityforms_user_registration"); + if(!empty($permission)) + $menus[] = array("name" => "gf_user_registration", "label" => __("User Registration", "gravityformsuserregistration"), "callback" => array("GFUser", "user_registration_page"), "permission" => $permission); + + return $menus; + } + + // Creates or updates database tables. Will only run when version changes + private static function setup(){ + if(get_option("gf_user_registration_version") != self::$version) { + + //loading data lib + require_once(self::get_base_path() . "/data.php"); + + GFUserData::update_table(); + + // create signups table for non-multisite installs + if(!is_multisite()) { + require_once(self::get_base_path() . '/includes/signups.php'); + GFUserSignups::create_signups_table(); + } + + update_option("gf_user_registration_version", self::$version); + } + } + + // Adds feed tooltips to the list of tooltips + public static function tooltips($tooltips){ + $userregistration_tooltips = array( + "user_registration_gravity_form" => "
" . __("Gravity Form", "gravityformsuserregistration") . "
" . __("Select the Gravity Form you would like to use to register users for your WordPress website.", "gravityformsuserregistration"), + "user_registration_feed_type" => "
" . __("Action", "gravityformsuserregistration") . "
" . __("Select the type of feed you would like to create. \"Create\" feeds will create a new user. \"Update\" feeds will update users.", "gravityformsuserregistration"), + "user_registration_username" => "
" . __("Username", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the user's username.", "gravityformsuserregistration"), + "user_registration_firstname" => "
" . __("First Name", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the user's first name.", "gravityformsuserregistration"), + "user_registration_lastname" => "
" . __("Last Name", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the user's last name.", "gravityformsuserregistration"), + "user_registration_displayname" => "
" . __("Display Name", "gravityformsuserregistration") . "
" . __("Select how the user's name should be displayed publicly.", "gravityformsuserregistration"), + "user_registration_email" => "
" . __("Email Address", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the user's email address.", "gravityformsuserregistration"), + "user_registration_password" => "
" . __("Password", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the user's password.", "gravityformsuserregistration"), + "user_registration_role" => "
" . __("Role", "gravityformsuserregistration") . "
" . __("Select the role the user should be assigned.", "gravityformsuserregistration"), + "user_registration_notification" => "
" . __("Send Email?", "gravityformsuserregistration") . "
" . __("Specify whether to send the password to the new user by email. Enabled by default.", "gravityformsuserregistration"), + "user_registration_set_post_author" => "
" . __("Set As Post Author", "gravityformsuserregistration") . "
" . __("When a form submission creates a post and registers a user, set the new user as the post author. Enabled by default.", "gravityformsuserregistration"), + "user_registration_user_activation" => "
" . __("User Activation", "gravityformsuserregistration") . "
" . __("Send users an email with an activation link. Users are only registered once they have activated their accounts.", "gravityformsuserregistration"), + "user_registration_user_activation_type" => "
" . __("User Activation Type", "gravityformsuserregistration") . "
" . __("By Email: Send the user an email with an activation link.
Manually: Activate each user manually from the Pending Activations page.", "gravityformsuserregistration"), + "user_registration_condition" => "
" . __("Registration Condition", "gravityformsuserregistration") . "
" . __("When the registration condition is enabled, form submissions will only register the user when the condition is met. When disabled the user will not be registered.", "gravityformsuserregistration"), + "user_registration_paypal_user_options" => "
" . __("User Registration", "gravityformsuserregistration") . "
" . __("The selected form also has a User Registration feed. These options allow you to specify how you would like the PayPal and User Registration Add-ons to work together.", "gravityformsuserregistration"), + "user_registration_multisite_create_site" => "
" . __("Create Site", "gravityformsuserregistration") . "
" . __("When WordPress Multisite is enabled, checking this option will enable the creation of a new site on the network when a new user registers.", "gravityformsuserregistration"), + "user_registration_multisite_site_address" => "
" . __("Site Address", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the site address.", "gravityformsuserregistration"), + "user_registration_multisite_site_title" => "
" . __("Site Title", "gravityformsuserregistration") . "
" . __("Select the form field that should be used for the site title.", "gravityformsuserregistration"), + "user_registration_multisite_site_role" => "
" . __("Site Role", "gravityformsuserregistration") . "
" . __("Select role the user should be assigned on the newly created site.", "gravityformsuserregistration"), + "user_registration_multisite_root_role" => "
" . __("Current Site Role", "gravityformsuserregistration") . "
" . __("Select role the user should be assigned on the site they registered from. This option overrides the \"Role\" option under User Settings.", "gravityformsuserregistration") + ); + return array_merge($tooltips, $userregistration_tooltips); + } + + public static function user_registration_page(){ + + $view = RGForms::get('view'); + $id = RGForms::get('id'); + + if($view == 'edit') { + self::edit_page($id); + } else if($view == 'pending_activations') { + self::pending_activations_page($id); + } else { + self::list_page(); + } + + } + + // List Page + + private static function list_page() { + + if(!self::is_gravityforms_supported()){ + die(sprintf(__("User Registration Add-On requires Gravity Forms %s. Upgrade automatically on the %sPlugin page%s.", "gravityformsuserregistration"), self::$min_gravityforms_version, "", "")); + } + + $action = RGForms::post("action"); + $bulk_action = RGForms::post("bulk_action"); + + if($action == "delete"){ + check_admin_referer("list_action", "gf_user_registration_list"); + + $id = absint($_POST["action_argument"]); + GFUserData::delete_feed($id); + ?> +
+ +
+ +
+ +

+

+ + Add New +

+ +
+ + + + +
+
+ + + '; + ?> +
+
+ + + + + + + + + + + + + + + + + + + + + 0){ + foreach($settings as $setting){ + ?> + + + + + + + + + + + + +
"/>.png" alt="" title="" onclick="ToggleActive(this, ); " /> + " title=""> + + + +
+ ', ""); ?> +
+
+
+ + +
+ ",""); ?> +
+ + +
+ + + +

+ + + + + + +
+ onclick="if(jQuery(this).is(':checked')) { jQuery('#gf_userregistration_custom_reg_page_options').slideDown(); } else { jQuery('#gf_userregistration_custom_reg_page_options').slideUp(); }" /> + + +
+ + + + +
+ +
+ + " class="button-primary" style="margin-top:40px;" /> +
+ +
+ + +
+ +

+
+ '; + echo apply_filters("gform_user_registration_uninstall_button", $uninstall_button); + ?> +
+ + +
+ + + + +
+ +

+

+ +

+ + array(), "is_active" => true) : GFUserData::get_feed($id); + $is_validation_error = false; + $error_messages = array(); + $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; + + // if this is an existing feed and no feed type is specified, default to "create" + if($id && !rgars($config, 'meta/feed_type')) + $config['meta']['feed_type'] = 'create'; + + // handle submission + $is_submit = RGForms::post("gf_user_registration_submit"); + if(!empty($is_submit) && check_admin_referer('user_registration_edit_submit','user_registration_edit_submit')){ + + $form_id = RGForms::post("gf_user_registration_form"); + $config["form_id"] = absint($form_id); + + // feed action; set to create if blank for old feeds + $config["meta"]["feed_type"] = rgpost("feed_type") ? rgpost("feed_type") : 'create'; + + $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; + + // standard meta + $config["meta"]["username"] = $is_update_feed ? '' : rgpost("gf_user_registration_username"); + $config["meta"]["firstname"] = rgpost("gf_user_registration_firstname"); + $config["meta"]["lastname"] = rgpost("gf_user_registration_lastname"); + $config["meta"]["displayname"] = rgpost("gf_user_registration_displayname"); + $config["meta"]["email"] = rgpost("gf_user_registration_email"); + $config["meta"]["password"] = rgpost("gf_user_registration_password"); + $config["meta"]["role"] = rgpost("gf_user_registration_role"); + + // user meta + $json = stripslashes(RGForms::post("gf_user_meta")); + $config["meta"]["user_meta"] = GFCommon::json_decode($json); + + //clean user meta (workaround to avoid values being marked as array) + if(is_array($config["meta"]["user_meta"])){ + foreach($config["meta"]["user_meta"] as &$meta){ + if(is_array($meta["meta_value"])){ + $meta["meta_value"] = $meta["meta_value"][0]; + } + } + } + + // registration condition + $config['meta']['reg_condition_enabled'] = RGForms::post('gf_user_registration_enabled'); + $config['meta']['reg_condition_field_id'] = RGForms::post('gf_user_registration_field_id'); + $config['meta']['reg_condition_operator'] = RGForms::post('gf_user_registration_operator'); + $config['meta']['reg_condition_value'] = RGForms::post('gf_user_registration_value'); + + // additional meta options + $config['meta']['notification'] = RGForms::post('gf_user_registration_notification'); + $config['meta']['set_post_author'] = RGForms::post('gf_user_registration_set_post_author'); + $config['meta']['user_activation'] = $is_update_feed ? false : RGForms::post('gf_user_registration_user_activation'); + $config['meta']['user_activation_type'] = $is_update_feed || !$config['meta']['user_activation'] ? false : rgpost('gf_user_registration_user_activation_type'); + + // use to save custom config options (used by BuddyPress) + $config = apply_filters("gform_user_registration_save_config", $config); + + // deprecated in favor of new method for generating error messages, preserved for users who may be using this + $is_validation_error = apply_filters("gform_user_registration_config_validation", false, $config); + + if(!$config["meta"]["email"] && !$is_update_feed) + $error_messages[] = __('You must map the "Email Address" setting to a field.', 'gravityformsuserregistration'); + + if(!$config["meta"]["username"] && !$is_update_feed) + $error_messages[] = __('You must map the "Username" setting to a field.', 'gravityformsuserregistration'); + + $error_messages = apply_filters('gform_user_confirm_validation_error', $error_messages, $config); + + // validate and create/update feed + if(empty($error_messages)) { + $id = GFUserData::update_feed($id, $config["form_id"], $config["is_active"], $config["meta"]); + ?> + +
+

", "") ?>

+
+ + +
+

+
  • ', $error_messages); ?>
+
+ + +
+ + + + + +
+ +

Feed Settings

+ +
+ + +
+ +
> + + + + + +
+ +
+ +
> + +
+ +

User Settings

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + '{username}', + 'firstname' => '{first name}', + 'lastname' => '{last name}', + 'firstlast' => '{first name} {last name}', + 'lastfirst' => '{last name} {first name}' + ); + ?> + +
+ +
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ +
+ +

User Meta

+ +
+ +
+ + + +
+ +

Additional Options

+ +
+ + /> + +
+ +
+ + /> + +
+ +
+ + + + + onclick="ToggleUserActivation();" /> + + +
+ + + + + +
+ +
+ +
+ + +
+ /> + + +
"> + + + + + +
+
+ +
+ + + +
+ " class="button-primary"/> + " class="button" onclick="javascript:document.location='admin.php?page=gf_user_registration'" /> +
+ +
+ +
+ +
+ +
+ + + + + + + +

+ + + "; + $str .= self::get_field_drop_down_items($fields, $selected_field, $empty_option); + $str .= ""; + return $str; + } + + private static function get_field_drop_down_items($fields, $selected_field, $empty_option = true){ + + $str = ''; + + if($empty_option == true) + $str = ''; + + if(is_array($fields)){ + foreach($fields as $field){ + $field_id = $field[0]; + $field_label = $field[1]; + $selected = $field_id == $selected_field ? "selected='selected'" : ""; + $str .= ""; + } + } + + return $str; + } + + // Parse Request + + public static function maybe_activate_user() { + + if(rgget('page') != 'gf_activation') + return; + + require_once(self::get_base_path() . '/includes/activate.php'); + + exit(); + } + + // Buddy Press + + public static function add_buddypress_options($config, $form) { + ?> + +

+ +
+ + + + + true )); + + $buddypress_fields = array(); + $i = 0; + foreach($groups as $group) { + + if(!is_array($group->fields)) + continue; + + foreach($group->fields as $field) { + $buddypress_fields[$i]['name'] = $field->name; + $buddypress_fields[$i]['value'] = $field->id; + $i++; + } + } + + return $buddypress_fields; + } + + public static function save_buddypress_meta($config) { + + $json = stripslashes(RGForms::post("gf_buddypress_config")); + $config["meta"]["buddypress_meta"] = GFCommon::json_decode($json); + + return $config; + } + + public static function prepare_buddypress_data($user_id, $config, $entry) { + + // required for user to display in the directory + bp_update_user_meta($user_id, 'last_activity', true); + + $buddypress_meta = rgars($config, 'meta/buddypress_meta'); + + if(empty($buddypress_meta)) + return; + + $form = RGFormsModel::get_form_meta($entry['form_id']); + $buddypress_row = array(); + + $i = 0; + foreach($buddypress_meta as $meta_item) { + + $buddypress_row[$i]['field_id'] = $meta_item['meta_name']; + $buddypress_row[$i]['user_id'] = $user_id; + + // get GF and BP fields + $gform_field = RGFormsModel::get_field($form, $meta_item['meta_value']); + if(version_compare(BP_VERSION, '1.6', '<')) { + $bp_field = new BP_XProfile_Field(); + $bp_field->bp_xprofile_field($meta_item['meta_name']); + } else { + require_once(WP_PLUGIN_DIR . '/buddypress/bp-xprofile/bp-xprofile-classes.php'); + $bp_field = new BP_XProfile_Field($meta_item['meta_name']); + } + + // if bp field is a checkbox AND gf field is a checkbox, get array of input values + $input_type = RGFormsModel::get_input_type($gform_field); + if( in_array($bp_field->type, array('checkbox', 'multiselectbox')) && in_array($input_type, array('checkbox', 'multiselect')) ) { + $meta_value = RGFormsModel::get_lead_field_value($entry, $gform_field); + + if(!is_array($meta_value)) + $meta_value = explode(',', $meta_value); + + $meta_value = self::maybe_get_category_name($gform_field, $meta_value); + $meta_value = array_filter($meta_value, 'GFUser::not_empty'); + } + else if($bp_field->type == 'datebox' && $gform_field['type'] == 'date'){ + $meta_value = strtotime(self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry)); + } + else { + $meta_value = self::get_prepared_value($gform_field, $meta_item['meta_value'], $entry); + } + + $buddypress_row[$i]['value'] = $meta_value; + $buddypress_row[$i]['last_update'] = date( 'Y-m-d H:i:s' ); + $i++; + } + + GFUserData::insert_buddypress_data($buddypress_row); + } + + /** + * Believe this was added to trigger a notification in the BP activity feed for new signups. + * + * @param mixed $user_id + */ + public static function bp_user_signup($user_id) { + global $bp; + + // this function overwrites the default meta we've just added + remove_action( 'bp_core_activated_user', 'xprofile_sync_wp_profile' ); + + do_action( 'bp_core_activated_user', $user_id, null, new WP_User($user_id) ); + } + + // Multisite + + public static function add_multisite_section($config, $form, $is_validation_error) { + + get_current_site(); + + $form_fields = self::get_form_fields($form); + $multisite_options = rgar($config['meta'], 'multisite_options'); + + if(!self::is_root_site()) + return; + + ?> + + + +
+ +

+ +
+ + onclick="toggleNetworkOptions(this);" /> + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + + + errors['blogname'][0])) ? $validation_result['errors']->errors['blogname'][0] : false; + + if($error_msg != false) + $form = self::add_validation_failure($multisite_options['site_address'], $form, $error_msg); + + } + + // site title validation, only if on correct page + if($site_title_field['pageNumber'] == $pagenum){ + + $error_msg = (isset($validation_result['errors']->errors['blog_title'][0])) ? $validation_result['errors']->errors['blog_title'][0] : false; + + if($error_msg != false) + $form = self::add_validation_failure($multisite_options['site_title'], $form, $error_msg); + + } + + return $form; + } + + public static function create_new_multisite($user_id, $config, $lead, $password) { + global $current_site; + + $form = RGFormsModel::get_form_meta($lead['form_id']); + $ms_options = rgars($config, 'meta/multisite_options'); + $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; + $user = new WP_User($user_id); + + $password_field = rgars($config, 'meta/password'); + $set_password = $password_field && rgar($lead, $password_field); + $password = $password ? $password : rgar($lead, $password_field); + + // @review, verify what this is doing and notate here + if(!$set_password) + remove_filter('update_welcome_email', 'bp_core_filter_blog_welcome_email'); + + // is create site option enabled? + if(!$ms_options['create_site']) + return; + + $site_data = self::get_site_data($lead, $form, $config, $is_update_feed); + if(!$site_data) + return; + + // create the new site! + $blog_id = wpmu_create_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_id , array( 'public' => 1 ), $current_site->id); + + if(is_wp_error($blog_id)) + return; + + // add entry ID to site meta for new site + GFUserData::update_site_meta($blog_id, 'entry_id', $lead['id']); + + $dashboard_blog = get_dashboard_blog(); + if(!is_super_admin($user_id) && get_user_option('primary_blog', $user_id) == $dashboard_blog->blog_id) { + update_user_option($user_id, 'primary_blog', $blog_id, true); + } + + if(rgar($ms_options, 'site_role')) { + $user = new WP_User($user_id, null, $blog_id); + $user->set_role(rgar($ms_options, 'site_role')); + } + + $root_role = rgar($ms_options, 'root_role'); + + // if no root role, remove user from current site + if(!$root_role) { + remove_user_from_blog($user_id); + } + // otherwise, update their role on current site + else { + $user = new WP_User($user_id); + $user->set_role($root_role); + } + self::log_debug("Calling wpmu_welcome_notification to send multisite welcome - blog_id: {$blog_id} user_id: {$user_id}" ); + wpmu_welcome_notification($blog_id, $user_id, $password, $site_data['title'], array('public' => 1)); + self::log_debug("Done with wpmu_welcome_notification"); + + do_action('gform_site_created', $blog_id, $user_id, $lead, $config, $password); + + // return new blog ID + return $blog_id; + } + + public static function is_root_site() { + + global $current_blog, $current_site; + + if($current_site->blog_id != $current_blog->blog_id) + return false; + + return true; + } + + private static function get_paypal_config($form_id, $entry){ + if(!class_exists('GFPayPal')) + return false; + + if(method_exists("GFPayPal", "get_config_by_entry")){ + return GFPayPal::get_config_by_entry($entry); + } + else{ + return GFPayPal::get_config($form_id); + } + } + + // Hook into Gravity Forms + public static function gf_create_user($entry, $form, $fulfilled = false) { + self::log_debug("in gf_create_user"); + global $wpdb; + + // if the entry is marked as spam + if(rgar($entry, 'status') == 'spam') + return; + + $config = self::get_active_config($form, $entry); + $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; + + // if there is no registration feed or the feed is not active, abandon ship + if(!$config || !$config['is_active']) + return; + + // if PayPal Add-on was used for this entry, integrate + $paypal_config = self::get_paypal_config($form["id"], $entry); + $delay_paypal_registration = 0; + if($paypal_config) { + //$paypal_config = self::get_paypal_config($form["id"], $entry); + $order_total = GFCommon::get_order_total($form, $entry); + + // delay the registration IF: + // - the delay registration option is checked + // - the order total does NOT equal zero (no delay since there will never be a payment) + // - the payment has not already been fulfilled + $delay_paypal_registration = $paypal_config['meta']['delay_registration']; + if($paypal_config && $delay_paypal_registration && $order_total != 0 && !$fulfilled) + return; + } + + // provide filter to allow add-ons to disable registration if needed + $disable_registration = apply_filters('gform_disable_registration', false, $form, $entry, $fulfilled); + + if($disable_registration) + return; + + $user_data = self::get_user_data($entry, $form, $config, $is_update_feed); + if(!$user_data) + return; + + $user_activation = rgars($config, 'meta/user_activation'); + + // if about to create user, check if activation required... only use activation if payment is not fulfilled by payment + //if manual activation and paypal set to delay registration and paypal fulfilled, need to put in signups table + if(!$is_update_feed && $user_activation && !$fulfilled || (!$is_update_feed && $user_activation && $fulfilled && $delay_paypal_registration) ) { + + require_once(self::get_base_path() . '/includes/signups.php'); + GFUserSignups::prep_signups_functionality(); + + $meta = array('lead_id' => $entry['id'], 'user_login' => $user_data['user_login'], 'email' => $user_data['user_email']); + $ms_options = rgars($config, 'meta/multisite_options'); + + // save current user details in wp_signups for future activation + if(is_multisite() && $ms_options['create_site'] && $site_data = self::get_site_data($entry, $form, $config)) { + wpmu_signup_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_data['user_login'], $user_data['user_email'], $meta); + } else { + // wpmu_signup_user() does the following sanitization of the user_login before saving it to the database, + // we can run this same code here to allow successful retrievel of the activation_key without actually + // changing the user name when it is activated. 'd smith' => 'dsmith', but when activated, username is 'd smith'. + $user_data['user_login'] = preg_replace( '/\s+/', '', sanitize_user( $user_data['user_login'], true ) ); + self::log_debug("Calling wpmu_signup_user (sends email with activation link) with login: " . $user_data['user_login'] . " email: " . $user_data['user_email'] . " meta: " . print_r($meta, true)); + wpmu_signup_user($user_data['user_login'], $user_data['user_email'], $meta); + self::log_debug("Done with wpmu_signup_user"); + } + + $activation_key = $wpdb->get_var($wpdb->prepare("SELECT activation_key FROM $wpdb->signups WHERE user_login = %s ORDER BY registered DESC LIMIT 1", $user_data['user_login'])); + + // used for filtering on activation listing UI + GFUserSignups::add_signup_meta($entry['id'], $activation_key); + + // abort current sign up, user must activate + return; + } + + if($is_update_feed) { + self::update_user($entry, $form, $config); + } else { + //only run create_user when manual/email activation NOT set + if (!$user_activation){ + self::log_debug("in gf_create_user - calling create_user"); + self::create_user($entry, $form, $config); + } + } + + } + + public static function create_user($lead, $form, $config = false) { + self::log_debug("in create_user with form id " . $form["id"] . " and lead: " . print_r($lead, true)); + if(!$config) + $config = self::get_active_config($form, $lead); + + $meta = rgar($config, 'meta'); + $user_data = self::get_user_data($lead, $form, $config); + $user_id = self::user_login_exists($user_data['user_login']); // @review, may not needs this here since we will likely handle updating user differently + + // create the user and password, then add user meta + if(!$user_id && empty($user_data['password'])) { + + $user_data['password'] = wp_generate_password(); + self::log_debug("calling wp_create_user for login " . $user_data['user_login'] . " with email " . $user_data['user_email']); + $user_id = wp_create_user($user_data['user_login'], $user_data['password'], $user_data['user_email']); + + if(is_wp_error($user_id)) + return; + + update_user_option($user_id, 'default_password_nag', true, false); + self::add_user_meta($user_id, $config, $form, $lead, array()); + + } + else if(!$user_id) { + self::log_debug("calling wp_create_user for login " . $user_data['user_login'] . " with email " . $user_data['user_email']); + $user_id = wp_create_user($user_data['user_login'], $user_data['password'], $user_data['user_email']); + if(is_wp_error($user_id)) + return; + + if(rgar($meta, 'password')) + GFUserData::remove_password($form['id'], $lead['id'], rgar($meta, 'password')); + + self::add_user_meta($user_id, $config, $form, $lead, array()); + + } + else { + + // if user with this username already exists, abort user registration + return; + + } + + //updating display name (after user meta because of dependency) + $user_data['ID'] = $user_id; + $user_data['display_name'] = self::get_display_name( $user_id, $config ); + wp_update_user($user_data); + + if(rgar($meta, 'role')) { + $user = new WP_User($user_id); + $user->set_role(rgar($meta, 'role')); + } + + // set post author + if(!empty($lead['post_id']) && rgar($meta, 'set_post_author')) + self::attribute_post_author($user_id, $lead['post_id']); + + // send notifications + self::log_debug("Calling wp_new_user_notification for user id {$user_id}"); + if(rgar($meta, 'notification')) { + wp_new_user_notification($user_id, $user_data['password']); + } else { + // sending a blank password only sends notification to admin + wp_new_user_notification($user_id, ""); + } + self::log_debug("Done with wp_new_user_notification - email with username should have been sent."); + + do_action('gform_user_registered', $user_id, $config, $lead, $user_data['password']); + + $user = new WP_User( $user_id ); + $first_name = $user->get('first_name'); + $last_name = $user->get('last_name'); + + // return array with user_id, user_login, user_email, and password + return array_merge(array('user_id' => $user_id), $user_data); + } + + /** + * Update the user based on the currently submitted lead. + * + * Update the user meta first as the display name is dependent on the first and last name user meta. Afterwards, + * update the "core" user properties. + * + * @param $lead + * @param $form + * @param bool $config + * @return array + */ + public static function update_user($lead, $form, $config = false) { + + if(!$config) + $config = self::get_active_config($form, $lead); + + $meta = rgar( $config, 'meta' ); + + $user_id = apply_filters('gform_user_registration_update_user_id', $lead['created_by'], $lead, $form, $config ); + $user_id = apply_filters("gform_user_registration_update_user_id_{$form['id']}", $user_id, $lead, $form, $config ); + + // update user meta before display name due to dependency + self::add_user_meta( $user_id, $config, $form, $lead, array() ); + + // refreshing $user variable because it might have changed during add_user_meta + $user_obj = new WP_User( $user_id ); + $user = get_object_vars( $user_obj->data ); + $user_data = self::get_user_data( $lead, $form, $config, true ); + + $user['user_email'] = $user_data['user_email']; + $user['display_name'] = self::get_display_name( $user['ID'], $config ); + + // if password provided, store it for update in $user array and then remove from $lead + if( $user_data['password'] ) { + $user['user_pass'] = $user_data['password']; + GFUserData::remove_password( $form['id'], $lead['id'], rgar($meta, 'password') ); + } else { + unset($user['user_pass']); + } + + $user_id = wp_update_user($user); + + if( rgar($meta, 'role') ) { + $user_obj->set_role(rgar($meta, 'role')); + } + + do_action('gform_user_updated', $user_id, $config, $lead, $user_data['password']); + + // return array with user_id, user_login, user_email, and password + return array_merge(array('user_id' => $user_id), $user_data); + } + + public static function get_user_data($lead, $form, $config, $is_update_feed = false) { + + $user_email = self::get_meta_value('email', $config, $form, $lead); + + if($is_update_feed) { + $user_obj = new WP_User(rgar($lead, 'created_by')); + $user_login = $user_obj->get('user_login'); + $user_email = $user_email ? $user_email : $user_obj->get('user_email'); + } else { + $user_login = apply_filters("gform_username_{$form['id']}", + apply_filters('gform_username', self::get_meta_value('username', $config, $form, $lead), $config, $form, $lead), + $config, $form, $lead ); + } + + $password = self::get_meta_value('password', $config, $form, $lead); + + if(empty($user_login) || empty($user_email)) + return false; + + return array('user_login' => $user_login, 'user_email' => $user_email, 'password' => $password); + } + + public static function get_site_data($lead, $form, $config, $is_update_feed = false) { + global $current_site, $domain, $base; + + $ms_options = rgars($config, 'meta/multisite_options'); + $user_data = self::get_user_data($lead, $form, $config, $is_update_feed); + + // get the blog address + $blog_address = ''; + $address = rgar($lead, $ms_options['site_address']); + if(!preg_match( '/(--)/', $address) && preg_match('|^([a-zA-Z0-9-])+$|', $address) ) + $blog_address = strtolower($address); + + // get the site title and user email + $blog_title = self::get_meta_value('site_title', $ms_options, $form, $lead); + + // final check to make sure our essentials are good to go + if(empty($blog_address) || empty($user_data['user_email']) || !is_email($user_data['user_email'])) + return; + + if ( is_subdomain_install() ) { + $blog_domain = $blog_address . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); + $path = $current_site->path; + } else { + $blog_domain = $current_site->domain; + $path = trailingslashit($current_site->path) . $blog_address . '/'; + } + + return array('domain' => $blog_domain, 'path' => $path, 'title' => $blog_title, 'email' => $user_data['user_email']); + } + + public static function user_login_exists($user_login) { + if(!function_exists('username_exists')) + require_once(ABSPATH . WPINC . "/registration.php"); + + return username_exists($user_login); + } + + public static function gf_process_user($lead_id, $status, $prev_status) { + + // check if user has already been created for this lead + if(self::get_user_id_by_meta('entry_id', $lead_id) || !($prev_status == 'spam' && $status == 'active')) + return; + + $entry = RGFormsModel::get_lead($lead_id); + $form = RGFormsModel::get_form_meta($entry['form_id']); + self::log_debug("in gf_process_user - calling gf_create_user"); + self::gf_create_user($entry, $form); + + } + + private static function add_user_meta($user_id, $config, $form, $entry, $name_fields) { + + $standard_meta = array( + 'firstname' => 'first_name', + 'lastname' => 'last_name' + ); + + foreach($standard_meta as $meta_key => $wp_meta_key) { + if(self::is_meta_key_mapped($meta_key, $config)){ + update_user_meta($user_id, $wp_meta_key, self::get_meta_value($meta_key, $config, $form, $entry)); + } + } + + // to track which entry the user was registered from + update_user_meta($user_id, 'entry_id', $entry['id']); + + // add custom user meta + $custom_meta = rgars($config, 'meta/user_meta'); + + if(is_array($custom_meta) && !empty($custom_meta)) { + $value = ''; + foreach($custom_meta as $custom_meta_item) { + + // skip empty meta items + if(!$custom_meta_item['meta_name'] || !$custom_meta_item['meta_value']) + continue; + + $field = RGFormsModel::get_field($form, $custom_meta_item['meta_value']); + $value = self::get_prepared_value($field, $custom_meta_item['meta_value'], $entry); + + if($custom_meta_item['meta_name'] == 'user_url' && $value) { + self::update_user_property($user_id, 'user_url', $value); + } + else if(rgblank($value)) { + delete_user_meta($user_id, $custom_meta_item['meta_name']); + } + else{ + update_user_meta($user_id, $custom_meta_item['meta_name'], $value); + } + } + } + + } + + public static function get_display_name($user_id, $config) { + + $meta = rgar($config, 'meta'); + $display_format = rgar($meta, 'displayname'); + $user = new WP_User($user_id); + + switch($display_format) { + case 'firstname': + $display_name = $user->first_name; + break; + case 'lastname': + $display_name = $user->last_name; + break; + case 'firstlast': + $display_name = $user->first_name . ' ' . $user->last_name; + break; + case 'lastfirst': + $display_name = $user->last_name . ' ' . $user->first_name; + break; + default: + $display_name = $user->user_login; + break; + } + + return $display_name; + } + + public static function update_display_name($user_id, $config) { + self::update_user_property($user_id, 'display_name', self::get_display_name( $user_id, $config ) ); + } + + public static function update_user_property($user_id, $prop_key, $prop_value) { + + if(!$user_id) + return; + + $user = new WP_User($user_id); + $userdata = $user->data; + + $new_userdata = new stdClass(); + $new_userdata->ID = $userdata->ID; + $new_userdata->$prop_key = $prop_value; + + $result = wp_update_user(get_object_vars($new_userdata)); + + $user = new WP_User($user_id); + $display_name = $user->get('display_name'); + + } + + /** + * Retrieves value from post to be populated as user meta. + * + * @param mixed $meta_key The meta key as specified in the $config + * @param mixed $meta The array of meta mappings stored in the $config + * @param mixed $form The current form object + * @param mixed $entry The current lead object + * @return mixed The value matching the meta mapping for the given meta key or if not found, an empty string + */ + public static function get_meta_value($meta_key, $meta, $form, $entry) { + + // support legacy usage where config was passed as $meta parameter + $meta = rgar($meta, 'meta') ? rgar($meta, 'meta') : $meta; + $is_username = $meta_key == 'username'; + + $field_id = rgar($meta, $meta_key); + $field = RGFormsModel::get_field($form, rgar($meta, $meta_key)); + + return !empty($field) ? self::get_prepared_value($field, rgar($meta, $meta_key), $entry, $is_username) : ''; + } + + public static function is_meta_key_mapped($meta_key, $config) { + return rgars($config, "meta/$meta_key"); + } + + public static function registration_condition_met($form, $config) { + + $config = $config["meta"]; + + $operator = isset($config["reg_condition_operator"]) ? $config["reg_condition_operator"] : ""; + $field = RGFormsModel::get_field($form, $config["reg_condition_field_id"]); + + if(empty($field) || !$config["reg_condition_enabled"]) + return true; + + $is_visible = !RGFormsModel::is_field_hidden($form, $field, array()); + $field_value = RGFormsModel::get_field_value($field, array()); + + $is_value_match = RGFormsModel::is_value_match($field_value, $config["reg_condition_value"], $operator); + $create_user = $is_value_match && $is_visible; + + return $create_user; + } + + public static function user_registration_validation( $validation_result ){ + + $form = $validation_result['form']; + $config = self::get_active_config($form); + $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; + $pagenum = rgpost( "gform_source_page_number_{$form['id']}" ); + $entry = self::convert_post_to_entry(); + + // if there is no registration feed or the registration condition is not met or feed is inactive, abandon ship + if( !$config || !self::registration_condition_met( $form, $config, $entry ) || !$config['is_active'] ) + return $validation_result; + + $username_field = RGFormsModel::get_field( $form, $config['meta']['username'] ); + $email_field = RGFormsModel::get_field( $form, $config['meta']['email'] ); + $password_field = RGFormsModel::get_field( $form, $config['meta']['password'] ); + + $is_username_hidden = RGFormsModel::is_field_hidden( $form, $username_field, array() ); + $is_email_hidden = RGFormsModel::is_field_hidden( $form, $email_field, array() ); + $is_password_hidden = RGFormsModel::is_field_hidden( $form, $password_field, array() ); + + $user_name = apply_filters("gform_username_{$form['id']}", + apply_filters('gform_username', self::get_meta_value('username', $config, $form, $entry), $config, $form, $entry), + $config, $form, $entry ); + $user_email = self::get_prepared_value($email_field, $config['meta']['email'], $entry); + $user_pass = RGForms::post('input_' . $config['meta']['password']); + + if( !function_exists('username_exists') ) + require_once(ABSPATH . WPINC . "/registration.php"); + + // if password field is not hidden and is on the current page we are validating, validate it + if( !$is_password_hidden && $password_field['pageNumber'] == $pagenum ) { + if( strpos( $user_pass, "\\" ) !== false ) + $form = self::add_validation_failure( $config['meta']['password'], $form, __('Passwords may not contain the character "\"', 'gravityformsuserregistration') ); + } + + if( is_multisite() ) { + + // if multisite is defined and true, lowercase name for validation + $user_name = strtolower( $user_name ); + $_POST['input_' . str_replace('.', '_', $config['meta']['username'])] = $user_name; + + $result = wpmu_validate_user_signup( $user_name, $user_email ); + $errors = $result['errors']->errors; + + // special validation overrides for update feeds + if( $is_update_feed ) { + + // do not validate username on update feeds + if( isset( $errors['user_name'] ) ) + unset( $errors['user_name'] ); + + // do not validate if email belongs to user + if( isset( $errors['user_email'] ) ) { + + for( $i = count( $errors['user_email'] ) - 1; $i >= 0; $i-- ) { + $error_message = $errors['user_email'][$i]; + // if user is re-submitting their own email address, don't give already used error + if( $error_message == __( 'Sorry, that email address is already used!' ) && self::is_users_email( $user_email ) ){ + unset( $errors['user_email'][$i] ); + } + //made as a separate else for ease of readability + elseif ( $error_message == __( 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.') && self::is_users_email( $user_email ) ){ + unset( $errors['user_email'][$i] ); + } + } + + // if no other user email errors remain, unset + if( count( $errors['user_email'] ) <= 0 ) + unset( $errors['user_email'] ); + + } + + } + + if( !empty( $errors ) ) { + + foreach( $errors as $type => $error_msgs ) { + foreach( $error_msgs as $error_msg ) { + switch( $type ) { + case 'user_name': + if( !$is_username_hidden && $username_field['pageNumber'] == $pagenum ) + $form = self::add_validation_failure( $config['meta']['username'], $form, $error_msg ); + break; + case 'user_email': + if( !$is_email_hidden && $email_field['pageNumber'] == $pagenum ) + $form = self::add_validation_failure( $config['meta']['email'], $form, $error_msg ); + break; + } + } + } + + } + + } + else { + + $username_exists = username_exists( $user_name ); + $email_exists = email_exists( $user_email ); + + if( !$is_email_hidden && $email_field['pageNumber'] == $pagenum ) { + + if( !$is_update_feed && $email_exists ) { + $form = self::add_validation_failure($config['meta']['email'], $form, __('This email address is already registered', 'gravityformsuserregistration') ); + } else if( $is_update_feed && $email_exists && !self::is_users_email( $user_email ) ) { + $form = self::add_validation_failure($config['meta']['email'], $form, __('This email address is already registered', 'gravityformsuserregistration') ); + } + + if( !$user_email ) + $form = self::add_validation_failure($config['meta']['email'], $form, __('The email address can not be empty', 'gravityformsuserregistration') ); + + } + + // do not validate the user name if this is an update feed, if the user name field is hidden or if we are not on the correct page + if( !$is_update_feed && !$is_username_hidden && $username_field['pageNumber'] == $pagenum ) { + + if($username_exists) + $form = self::add_validation_failure($config['meta']['username'], $form, __('This username is already registered', 'gravityformsuserregistration') ); + + if( !validate_username($user_name) ) + $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores, dashes and spaces', 'gravityformsuserregistration') ); + + if( self::is_bp_active() && strpos($user_name, " ") !== false ) + $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes', 'gravityformsuserregistration') ); + + if( empty( $user_name ) ) + $form = self::add_validation_failure($config['meta']['username'], $form, __('The username can not be empty', 'gravityformsuserregistration') ); + + } + + } + + $form = apply_filters('gform_user_registration_validation', $form, $config, $pagenum); + $validation_result["is_valid"] = self::is_form_valid( $form ); + $validation_result["form"] = $form; + + return $validation_result; + } + + private static function get_prepared_value($field, $input_id, $entry, $is_username = false){ + + $space = (self::is_bp_active() && $is_username) ? '' : ' '; + + switch(RGFormsModel::get_input_type($field)){ + case "name": + if(strpos($input_id, '.') === false){ + $prefix = trim(rgar($entry, "{$input_id}.2")); + $first = trim(rgar($entry, "{$input_id}.3")); + $last = trim(rgar($entry, "{$input_id}.6")); + $suffix = trim(rgar($entry, "{$input_id}.8")); + + $name = $prefix; + $name .= !empty($name) && !empty($first) ? $space . $first : $first; + $name .= !empty($name) && !empty($last) ? $space . $last : $last; + $name .= !empty($name) && !empty($suffix) ? $space . $suffix : $suffix; + + return $name; + } + else{ + return rgar($entry, $input_id); + } + break; + + case "address" : + if(strpos($input_id, '.') === false){ + $street_value = trim(rgar($entry, "{$input_id}.1")); + $street2_value = trim(rgar($entry, "{$input_id}.2")); + $city_value = trim(rgar($entry, "{$input_id}.3")); + $state_value = trim(rgar($entry, "{$input_id}.4")); + $zip_value = trim(rgar($entry, "{$input_id}.5")); + $country_value = trim(rgar($entry, "{$input_id}.6")); + + $address = $street_value; + $address .= !empty($address) && !empty($street2_value) ? ", $street2_value" : $street2_value; + $address .= !empty($address) && (!empty($city_value) || !empty($state_value)) ? ", $city_value" : $city_value; + $address .= !empty($address) && !empty($city_value) && !empty($state_value) ? ", $state_value" : $state_value; + $address .= !empty($address) && !empty($zip_value) ? " $zip_value" : $zip_value; + $address .= !empty($address) && !empty($country_value) ? " $country_value" : $country_value; + + return $address; + } + else{ + return rgar($entry, $input_id); + } + break; + + default: + $val = rgar($entry, $input_id); + + //Post category fields come with Category Name and ID in the value (i.e. Austin:51). Only returning the name + $val = self::maybe_get_category_name($field, $val); + + return $val; + break; + } + + } + + // simulates entry format for inputs + private static function convert_post_to_entry(){ + + $entry = array(); + + foreach($_POST as $key => $value){ + + $id = str_replace('_', '.', str_replace('input_', '', $key)); + $entry[$id] = $value; + + } + + return $entry; + } + + public static function add_validation_failure($field_id, $form, $message = "This field does not validate.") { + + if(is_numeric($field_id)) + $field_id = intval($field_id); + + for($i = 0; $i < count($form['fields']); $i++ ) { + if($form['fields'][$i]['id'] == $field_id) { + $form["fields"][$i]["failed_validation"] = true; + $form["fields"][$i]["validation_message"] = apply_filters('gform_user_registration_validation_message', $message, $form); + } + } + + return $form; + } + + private static function is_form_valid($form) { + + foreach($form['fields'] as $field) { + if($field['failed_validation'] == true) { + return false; + } + } + + return true; + } + + private static function get_entry_value($field_id, $entry, $name_fields){ + foreach($name_fields as $name_field){ + if($field_id == $name_field["id"]){ + $value = RGFormsModel::get_lead_field_value($entry, $name_field); + return GFCommon::get_lead_field_display($name_field, $value); + } + } + + return $entry[$field_id]; + } + + public static function attribute_post_author($user_id, $post_id) { + + $post = get_post($post_id); + + if(empty($post)) + return; + + $post->post_author = $user_id; + + wp_update_post($post); + + } + + // Hook into GF PayPal Plugin + + public static function add_paypal_user_registration_options($config, $form) { + global $wp_roles; + + require_once(self::get_base_path() . '/data.php'); + + // activate user registration tooltips for integration with PayPal plugin + add_filter('gform_tooltips', array('GFUser', 'tooltips')); + + $id = rgget('id'); + + $registration_config = $form ? self::get_active_config($form) : false; + $registration_feeds = GFUserData::get_feeds(); + $registration_forms = array(); + + foreach($registration_feeds as $feed) { + $registration_forms[] = $feed['form_id']; + } + + $json_registration_forms = GFCommon::json_encode($registration_forms); + + if(empty($json_registration_forms)) + $json_registration_forms = '[]'; + + $roles = array_keys($wp_roles->roles); + $display_registration_options = !empty($registration_config) ? '' : 'display:none;'; + $display_multisite_options = (is_multisite() && self::is_root_site() && rgars($config, 'meta/type') == 'subscription') ? '' : 'display:none;'; + + ?> + + + +
+ + +
    + + + +
  • + /> + +
  • + +
  • > + onclick="var action = this.checked ? '' : ''; jQuery('#gf_paypal_update_user_action').val(action);" /> + + +
  • + + + +
  • + onclick="var action = this.checked ? 'deactivate' : ''; jQuery('#gf_paypal_update_site_action').val(action);" /> + + +
  • + +
+
+ + set_role($paypal_config['meta']['update_user_action']); + + } + + public static function downgrade_paypal_site($entry, $config) { + global $current_site; + + $action = $config['meta']['update_site_action']; + + if(!$action) + return; + + $site_id = GFUserData::get_site_by_entry_id($entry['id']); + + if(!$site_id) + return; + + switch($action){ + case 'deactivate': + do_action('deactivate_blog', $site_id); + update_blog_status($site_id, 'deleted', '1'); + break; + case 'delete': + require_once(ABSPATH . 'wp-admin/includes/ms.php'); + if($site_id != '0' && $site_id != $current_site->blog_id) + wpmu_delete_blog($site_id, true); + break; + } + + } + + // More Functions... + + public static function add_permissions(){ + global $wp_roles; + $wp_roles->add_cap("administrator", "gravityforms_user_registration"); + $wp_roles->add_cap("administrator", "gravityforms_user_registration_uninstall"); + } + + public static function is_users_email( $email, $user_id = false ) { + + if( !$user_id ) + $user_id = get_current_user_id(); + + $user = new WP_User( $user_id ); + + return $user->get( 'user_email' ) == $email; + } + + // Target of Member plugin filter. Provides the plugin with Gravity Forms lists of capabilities + public static function members_get_capabilities( $caps ) { + return array_merge($caps, array("gravityforms_user_registration", "gravityforms_user_registration_uninstall")); + } + + public static function get_config($form_id){ + if(!class_exists("GFUserData")) + require_once(self::get_base_path() . "/data.php"); + + //Getting user_registration settings associated with this transaction + $config = GFUserData::get_feed_by_form($form_id); + + //Ignore IPN messages from forms that are no longer configured with the PayPal add-on + if(!$config) + return false; + + return $config[0]; //only one feed per form is supported + } + + public static function get_active_config($form, $lead = false){ + require_once(self::get_base_path() . "/data.php"); + + $config = false; + + // if lead is provided, attempt to retrieve config from lead meta + if($lead) { + $config_id = gform_get_meta($lead['id'], 'user_registration_feed_id'); + $config = GFUserData::get_feed($config_id); + } + + // if no lead is provided or if meta retrieval fails, get all feeds and find the first feed that matches + if(!$config) { + + $configs = GFUserData::get_feeds_by_form($form["id"]); + if(!$configs) + return false; + + foreach($configs as $cnfg) { + if(self::registration_condition_met($form, $cnfg)) { + $config = $cnfg; + break; + } + } + + } + + // if lead is provided and a config is found, update lead meta with config ID + if($lead && $config && !$config_id) + gform_update_meta($lead['id'], 'user_registration_feed_id', $config['id']);; + + if($config) + return $config; + + return false; + } + + public static function uninstall(){ + + //loading data lib + require_once(self::get_base_path() . "/data.php"); + + if(!self::has_access("gravityforms_user_registration_uninstall")) + die(__("You don't have adequate permission to uninstall the User Registration Add-On.", "gravityformsuserregistration")); + + //droping all tables + GFUserData::drop_tables(); + + //removing options + delete_option("gf_user_registration_version"); + + //Deactivating plugin + $plugin = "gravityformsuserregistration/userregistration.php"; + deactivate_plugins($plugin); + update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); + } + + private static function is_gravityforms_installed(){ + return class_exists("RGForms"); + } + + private static function is_gravityforms_supported(){ + if(class_exists("GFCommon")){ + $is_correct_version = version_compare(GFCommon::$version, self::$min_gravityforms_version, ">="); + return $is_correct_version; + } + else{ + return false; + } + } + + protected static function has_access($required_permission){ + $has_members_plugin = function_exists('members_get_capabilities'); + $has_access = $has_members_plugin ? current_user_can($required_permission) : current_user_can("level_7"); + if($has_access) + return $has_members_plugin ? $required_permission : "level_7"; + else + return false; + } + + private static function get_form_fields($form, $is_update_feed = false){ + $fields = array(); + + if(is_array(rgar($form, 'fields'))){ + foreach($form["fields"] as $field){ + //TODO - research why we were limiting the update feed to not allow POST fields for mapping + //neither Dave nor Alex could remember why, this will result in a POST being created with each update + //but they have a POST field, they should expect that + //if($is_update_feed && GFCommon::is_post_field($field)) + // continue; + $inputs = rgar($field,"inputs"); + if(is_array($inputs) && !empty($inputs)){ + + if(RGFormsModel::get_input_type($field) == "address" || RGFormsModel::get_input_type($field) == "name") + $fields[] = array($field["id"], GFCommon::get_label($field) . " (" . __("Full" , "gravityformsuserregistration") . ")"); + + foreach($field["inputs"] as $input) + $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"])); + + } + //else if(!$field["displayOnly"]){ + else if(!rgar($field, 'displayOnly')){ + $fields[] = array($field["id"], GFCommon::get_label($field)); + } + + } + } + return $fields; + } + + private static function get_fields_by_type($form, $types){ + $fields = array(); + + if(is_array($form["fields"])){ + foreach($form["fields"] as $field){ + + // if not a field type we want, skip it + if(is_array($types)) { + if(!in_array($field["type"], $types) && !in_array($field['inputType'], $types)) + continue; + } else { + if($field["type"] != $types && rgar($field,'inputType') != $types) + continue; + } + $inputs = rgar($field,"inputs"); + if(is_array($inputs)){ + + foreach($inputs as $input) + $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"])); + } + else { + $fields[] = array($field["id"], GFCommon::get_label($field)); + } + + } + } + return $fields; + } + + private static function get_bp_gform_fields($form){ + $fields = array(); + + if(is_array($form["fields"])){ + foreach($form["fields"] as $field){ + + $inputs = rgar($field,"inputs"); + if(is_array($inputs) && !empty($inputs)){ + + if(RGFormsModel::get_input_type($field) == "checkbox") { + $fields[] = array($field["id"], GFCommon::get_label($field)); + continue; + } + + if(RGFormsModel::get_input_type($field) == "address" || RGFormsModel::get_input_type($field) == "name") + $fields[] = array($field["id"], GFCommon::get_label($field) . " (" . __("Full" , "gravityformsuserregistration") . ")"); + + foreach($inputs as $input) + $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"])); + + } + //else if(!$field["displayOnly"]){ + else if(!rgar($field, 'displayOnly')){ + $fields[] = array($field["id"], GFCommon::get_label($field)); + } + + } + } + + return $fields; + } + + private static function is_user_registration_page(){ + $current_page = trim(strtolower(RGForms::get("page"))); + return in_array($current_page, array("gf_user_registration")); + } + + public static function get_base_url(){ + return plugins_url(null, __FILE__); + } + + public static function get_base_path(){ + $folder = basename(dirname(__FILE__)); + return WP_PLUGIN_DIR . "/" . $folder; + } + + public static function print_rr($array) { + echo '
';
+        print_r($array);
+        echo '
'; + } + + public static function add_buddypress_hooks() { + + if(is_admin()){ + + // buddypress admin hooks + add_action("gform_user_registration_add_option_section", array("GFUser", "add_buddypress_options"), 10, 2); + add_filter("gform_user_registration_save_config", array("GFUser", "save_buddypress_meta")); + + } else { + + // buddypress non-admin hooks + add_action("gform_user_updated", array("GFUser", "prepare_buddypress_data"), 10, 3); + + } + + // as of UR 1.5 pending activations, the "gform_user_registered" hook can be fired both in the admin (when manually activating) + // pending activations and on the front-end (by default) + add_action("gform_user_registered", array("GFUser", "prepare_buddypress_data"), 10, 3); + add_action("gform_user_registered", array("GFUser", "bp_user_signup")); + + } + + public static function add_multisite_hooks() { + + if(is_admin()){ + + // multisite admin hooks + add_action("gform_user_registration_add_option_section", array("GFUser", "add_multisite_section"), 10, 3); + add_filter("gform_user_registration_save_config", array("GFUser", "save_multisite_config")); + add_filter("gform_user_registration_config_validation", array("GFUser", "validate_multisite_config"), 10, 2); + + } else { + + // multisite non-admin hooks + add_action("gform_user_registration_validation", array("GFUser", "validate_multisite_submission"), 10, 3); + add_action("gform_user_registered", array("GFUser", "create_new_multisite"), 10, 4); + add_action("gform_user_updated", array("GFUser", "create_new_multisite"), 10, 4); + + // add paypal ipn hooks for multisite + add_action("gform_subscription_canceled", array("GFUser", "downgrade_paypal_site"), 10, 2); + + } + + } + + public static function is_bp_active() { + return defined('BP_VERSION') ? true : false; + } + + /** + * Redirect to the custom registration page as specified in the User Registration settings. + * + * By default, this function checks if the user is accessing the default WP registration page + * "/wp-login.php?action=register" and if so, processes the redirect. + * + * If BuddyPress is active, it checks if the current page is the the BP registration page + * (as specified in the BP Page settings) and if so, processes the redirect. We also check + * to ensure that the User Registration Custom Registration Page ID is not the same as the + * BP Register Page ID. + * + */ + public static function custom_registration_page() { + global $bp; + + $action = rgget('action'); + $redirect = false; + + // if BP is active and this is the registration page, redirect + if(self::is_bp_active() && bp_is_register_page()) + $redirect = true; + + // if "wp-login.php?action=register", aka default WP registration page + $script_name = substr($_SERVER['SCRIPT_NAME'], -12, 12); // get last 12 characters of script name (we want wp-login.php); + if($script_name == 'wp-login.php' && $action == 'register') + $redirect = true; + + // add support for multi-site + $script_name = substr($_SERVER['SCRIPT_NAME'], -13, 13); // get last 12 characters of script name (we want wp-login.php); + if( is_multisite() && $script_name == 'wp-signup.php' ) + $redirect = true; + + if(!$redirect) + return; + + $ur_settings = get_option('gf_userregistration_settings'); + $reg_page_id = rgar($ur_settings, 'custom_reg_page'); + + if(empty($ur_settings) || !rgar($ur_settings, 'enable_custom_reg_page')) + return; + + // if BP is active, BP Register Page is set and BP Register Page ID is the same as the UR Register Page ID, cancel redirect + if(self::is_bp_active() && isset($bp->pages->register->id) && $bp->pages->register->id == $reg_page_id) + return; + + wp_redirect(get_permalink($reg_page_id)); + exit; + } + + public static function get_user_id_by_meta($key, $value) { + global $wpdb; + + $table_name = $wpdb->prefix . "usermeta"; + $user = $wpdb->get_var($wpdb->prepare("select user_id from $table_name where meta_key = %s && meta_value = %s", $key, $value)); + + return !empty($user) ? $user : false; + } + + private static function not_empty($value) { + return $value; + } + + public static function display_role_dropdown_options($selected_role, $no_role_option = false) { + + self::dropdown_roles( $selected_role ); + + if(!is_multisite() || !$no_role_option) + return; + + $selected = !$selected_role ? 'selected="selected"' : ''; + + echo ''; + + } + + public static function dropdown_roles( $selected_role ) { + add_filter( 'editable_roles', array( __class__, 'update_roles_order') ); + wp_dropdown_roles( $selected_role ); + remove_filter( 'editable_roles', array( __class__, 'update_roles_order') ); + } + + /** + * Modifies the order of roles by a custom array. A side-effect of this ordering is that custom roles + * will always appear after default WP roles. + * + * @param mixed $roles + */ + public static function update_roles_order( $roles ) { + + $role_order = array( 'subscriber', 'contributor', 'author', 'editor', 'administrator' ); + $role_order = array_reverse( $role_order, true ); + + foreach( $role_order as $role_slug ) { + + if( !array_key_exists( $role_slug, $roles ) ) + continue; + + $role = $roles[$role_slug]; + $roles = array_merge( array( $role_slug => $role ), $roles ); + + } + + return $roles; + } + + /* + * This function will check to ensure that the current install is a Network before + * returning a UR Network meta value + * + */ + public static function get_network_meta_value($meta_key, $config) { + + if(!is_multisite()); + return false; + + $network_meta = rgars($config, 'meta/multisite_options'); + + return rgar($network_meta, $meta_key); + } + + + public static function maybe_prepopulate_form($form) { + + $config = GFUserData::get_update_feed($form['id']); + + // if no feed, return form unmodified + if(!$config) { + return $form; + } else + // if the user is not logged in, add action to hide form and display error message + if( ! is_user_logged_in() ) { + add_action( 'gform_get_form_filter_' . $form['id'], array( 'GFUser', 'hide_form' ) ); + return $form; + } else { + // prepopulate the form + $form = GFUser::prepopulate_form($form, $config); + } + + return $form; + } + + public static function maybe_get_category_id($field, $category_name){ + + if($field["type"] == "post_category"){ + if(in_array(RGFormsModel::get_input_type($field) , array("multiselect", "checkbox"))){ + $category_names = explode(",", $category_name); + } + else{ + $category_names = array($category_name); + } + + $cat_ids = array(); + foreach($category_names as $name){ + $id = get_cat_ID($name); + if(!empty($id)) + $cat_ids[] = $id; + } + + return implode(",", $cat_ids); + } + + return $category_name; + } + + public static function maybe_get_category_name($field, $entry_value){ + if($field["type"] == "post_category"){ + if(is_array($entry_value)){ + foreach($entry_value as &$value){ + //$entry_value[$key] = explode(":", $value); + list($value, $cat_id) = explode(":", $value); + } + } + else{ + list($entry_value, $cat_id) = explode(":", $entry_value); + } + } + + return $entry_value; + } + + public static function prepopulate_form($form, $config) { + global $bp; + + $mapped_fields = array(); + $meta = rgar($config, 'meta'); + $user = wp_get_current_user(); + + foreach(array('username', 'lastname', 'firstname', 'email') as $meta_key) { + $field_id = rgar($meta, $meta_key); + if($field_id) { + $mapped_fields[(string)$field_id] = $user->get(self::convert_to_wp_meta_key($meta_key)); + } + } + + $custom_meta = rgars($config, 'meta/user_meta') ? rgars($config, 'meta/user_meta') : array(); + foreach($custom_meta as $meta_item) { + if(rgar($meta_item, 'meta_value')) { + $field_id = rgar($meta_item, 'meta_value'); + $mapped_fields[(string)$field_id] = $user->get(rgar($meta_item, 'meta_name')); + } + } + + if(function_exists("xprofile_get_field_data")){ + $buddypress_meta = rgars($config, 'meta/buddypress_meta') ? rgars($config, 'meta/buddypress_meta') : array(); + foreach($buddypress_meta as $meta_item) { + if(rgar($meta_item, 'meta_value')) { + $field_id = rgar($meta_item, 'meta_value'); + $mapped_fields[(string)$field_id] = xprofile_get_field_data(rgar($meta_item, 'meta_name'), $user->ID); + } + } + } + + // get all fields for cheap check inside field loop + $mapped_field_ids = array_map('intval', array_keys($mapped_fields)); + + foreach($form['fields'] as &$field) { + + if(!in_array($field['id'], $mapped_field_ids)) + continue; + + $value = false; + + switch(RGFormsModel::get_input_type($field)) { + + case 'fileupload': + + $value = rgar($mapped_fields, $field['id']); + $path_info = pathinfo($value); + + // check if file has been "deleted" via form UI + $upload_files = json_decode( rgpost('gform_uploaded_files'), ARRAY_A ); + $input_name = "input_{$field['id']}"; + if( is_array( $upload_files ) && array_key_exists( $input_name, $upload_files ) && !$upload_files[$input_name] ) + continue; + + // if $uploaded_files array is not set for this form at all, init as array + if( !isset( RGFormsModel::$uploaded_files[$form['id']] ) ) + RGFormsModel::$uploaded_files[$form['id']] = array(); + + // check if this field's key has been set in the $uploaded_files array, if not add this file (otherwise, a new image may have been uploaded so don't overwrite) + if( !isset( RGFormsModel::$uploaded_files[$form['id']]["input_{$field['id']}"] ) ) + RGFormsModel::$uploaded_files[$form['id']]["input_{$field['id']}"] = $path_info['basename']; + + break; + + case 'checkbox': + + $value = rgar($mapped_fields, $field['id']); + $cb_values = array(); + + if(is_array($value)) { + $cb_values = $value; + } else { + foreach($field['inputs'] as &$input) { + $cb_values[] = rgar($mapped_fields, (string)$input['id']); + } + } + + $value = implode(',', $cb_values); + + break; + + case 'list': + + $value = maybe_unserialize(rgar($mapped_fields, $field['id'])); + $list_values = array(); + + if(is_array($value)) { + foreach($value as $vals) { + if( ! is_array( $vals ) ) + $vals = array( $vals ); + $list_values = array_merge($list_values, array_values($vals)); + } + $value = $list_values; + } + + break; + + case 'date': + $value = GFCommon::date_display( rgar($mapped_fields, $field['id']) , $field['dateFormat'], false); + break; + + default: + + // handle complex fields + if(is_array(rgar($field, 'inputs'))) { + + foreach($field['inputs'] as &$input) { + $filter_name = self::prepopulate_input( $input['id'], rgar($mapped_fields, (string)$input['id'])); + $field['allowsPrepopulate'] = true; + $input['name'] = $filter_name; + } + + } else { + + $value = is_array(rgar($mapped_fields, $field['id'])) ? implode(',', rgar($mapped_fields, $field['id'])) : rgar($mapped_fields, $field['id']); + + } + + } + + if (rgblank($value)){ + continue; + } + + $value = self::maybe_get_category_id($field, $value); + $filter_name = self::prepopulate_input($field['id'], $value); + $field['allowsPrepopulate'] = true; + $field['inputName'] = $filter_name; + + } + + return $form; + } + + public static function prepopulate_input($input_id, $value) { + + $filter_name = 'gfur_field_' . str_replace('.', '_', $input_id); + add_filter("gform_field_value_{$filter_name}", create_function("", "return maybe_unserialize('" . str_replace("'", "\'", maybe_serialize($value)) . "');")); + + return $filter_name; + } + + public static function handle_existing_images_submission( $form ) { + global $_gf_uploaded_files; + + // get UR config + // get all fileupload fields mapped in the UR config + // foreach loop through and see if the image has been: + // - resubmitted populate the existing image data into the $_gf_uploaded_files + // - deleted do nothing + // - new image submitted do nothing + + if( empty( $_gf_uploaded_files ) ) + $_gf_uploaded_files = array(); + + $config = GFUserData::get_update_feed( $form['id'] ); + + if( !$config ) + return; + + $user_meta = rgars( $config, 'meta/user_meta' ); + $upload_files = json_decode( rgpost('gform_uploaded_files'), ARRAY_A ); + + foreach( $user_meta as $meta_item ) { + + $field = RGFormsModel::get_field( $form, $meta_item['meta_value'] ); + $input_name = "input_{$field['id']}"; + + if( RGFormsModel::get_input_type( $field ) != 'fileupload' ) + continue; + + if( self::is_prepopulated_file_upload( $form['id'], $input_name ) ) { + $_gf_uploaded_files[$input_name] = get_user_meta( get_current_user_id(), $meta_item['meta_name'], true ); + } + + } + + } + + public static function is_new_file_upload( $form_id, $input_name ) { + + $file_info = RGFormsModel::get_temp_filename( $form_id, $input_name ); + $temp_filepath = RGFormsModel::get_upload_path($form_id) . "/tmp/" . $file_info["temp_filename"]; + + // check if file has already been uploaded by previous step + if( $file_info && file_exists( $temp_filepath ) ){ + return true; + } + // check if file is uplaoded on current step + else if ( !empty($_FILES[$input_name]["name"]) ) { + return true; + } + + return false; + } + + public static function is_prepopulated_file_upload( $form_id, $input_name ) { + + // prepopulated files will be stored in the 'gform_uploaded_files' field + $uploaded_files = json_decode( rgpost('gform_uploaded_files'), ARRAY_A ); + + // file is prepopulated if it is present in the 'gform_uploaded_files' field AND is not a new file upload + $in_uploaded_files = is_array( $uploaded_files ) && array_key_exists( $input_name, $uploaded_files ) && !empty( $uploaded_files[$input_name] ); + $is_prepopulated = $in_uploaded_files && !self::is_new_file_upload( $form_id, $input_name ); + + return $is_prepopulated; + } + + public static function hide_form($form_string) { + + // should only hide the current form + remove_action('gform_get_form_filter', array('GFUser', 'hide_form')); + + return __('Oops! You need to be logged in to use this form.', 'gravityformsuserregistration'); + } + + /** + * Adjusts provided User Registration meta key the corresponding match WordPress meta key. + * Ideally, plugin should have used these from the start, but hind sight is 20/20 and experience is delicious. + * + * @param mixed $key + * @return mixed + */ + public static function convert_to_wp_meta_key($key) { + switch($key) { + case 'username': + return 'user_login'; + case 'firstname': + return 'first_name'; + case 'lastname': + return 'last_name'; + case 'email': + return 'user_email'; + } + return $key; + } + + /** + * Get available forms based on form ID and feed type. + * + */ + public static function get_available_forms() { + + $feed_type = rgpost('feed_type'); + $feed_id = rgpost('feed_id'); + $forms = GFUserData::get_available_forms($feed_type, $feed_id); + + die(self::create_form_select_options($forms)); + } + + public static function create_form_select_options($forms, $config = array()) { + + $str = '' . "\n"; + + foreach($forms as $form) { + $selected = $form->id == rgar($config, 'form_id') ? 'selected="selected"' : ''; + $str .= '' . "\n"; + } + + return $str; + } + + public static function is_timestamp($timestamp) { + return ((string) (int) $timestamp === $timestamp) + && ($timestamp <= PHP_INT_MAX) + && ($timestamp >= ~PHP_INT_MAX); + } + + + /** + * Handle activating pending activation from entry detail page. + */ + public static function is_lead_pending_activation($lead) { + global $wpdb; + require_once(self::get_base_path() . '/includes/pending_activations.php'); + return GFUserPendingActiviations::get_pending_activations($lead['form_id'], array('lead_id' => $lead['id'], 'get_total' => true)) > 0; + } + + public static function entry_activation_button($form_id, $lead) { + + if(!self::is_lead_pending_activation($lead)) + return; + + require_once(self::get_base_path() . '/includes/signups.php'); + + $lead_id = rgar($lead, 'id'); + $activation_key = GFUserSignups::get_lead_activation_key($lead_id); + + ?> + + + + + + get_error_message(); + } + + echo $error_message; + + exit; + } + + + + public static function get_user_meta_keys($exclude = array()) { + global $wpdb; + + $keys = array(); + $raw_keys = $wpdb->get_results("select distinct meta_key from {$wpdb->prefix}usermeta"); + + foreach($raw_keys as $key) { + if(!in_array($key->meta_key, $exclude)) + $keys[$key->meta_key] = $key->meta_key; + } + + return $keys; + } + + public static function escape_single_quote($value) { + return str_replace("'", "\'", $value); + } + + + + // HELPER FUNCTIONS // + + public static function is_pending_activation_enabled( $feed ) { + return rgars( $feed, 'meta/user_activation' ) == true; + } + + public static function get_pending_activation_forms() { + + $forms = RGFormsModel::get_forms( null, 'title' ); + $feeds = GFUserData::get_feeds(); + + $available_form_ids = array(); + foreach( $feeds as $feed ) { + if( self::is_pending_activation_enabled( $feed ) ) + $available_form_ids[] = $feed['form_id']; + } + + $available_form_ids = array_unique( $available_form_ids ); + + $available_forms = array(); + foreach( $forms as $form ) { + if( in_array( $form->id, $available_form_ids ) ) + $available_forms[] = $form; + } + + return $available_forms; + } + + public static function set_logging_supported($plugins) + { + $plugins[self::$slug] = "User Registration"; + return $plugins; + } + + private static function log_error($message){ + if(class_exists("GFLogging")) + { + GFLogging::include_logger(); + GFLogging::log_message(self::$slug, $message, KLogger::ERROR); + } + } + + private static function log_debug($message){ + if(class_exists("GFLogging")) + { + GFLogging::include_logger(); + GFLogging::log_message(self::$slug, $message, KLogger::DEBUG); + } + } + +} + + + + + +if(!function_exists("rgget")){ +function rgget($name, $array=null){ + if(!isset($array)) + $array = $_GET; + + if(isset($array[$name])) + return $array[$name]; + + return ""; +} +} + +if(!function_exists("rgpost")){ +function rgpost($name, $do_stripslashes=true){ + if(isset($_POST[$name])) + return $do_stripslashes ? stripslashes_deep($_POST[$name]) : $_POST[$name]; + + return ""; +} +} + +if(!function_exists("rgar")){ +function rgar($array, $name){ + if(isset($array[$name])) + return $array[$name]; + + return ''; +} +} + +if(!function_exists("rgars")){ +function rgars($array, $name){ + $names = explode("/", $name); + $val = $array; + foreach($names as $current_name){ + $val = rgar($val, $current_name); + } + return $val; +} +} + +if(!function_exists("rgempty")){ +function rgempty($name, $array = null){ + if(!$array) + $array = $_POST; + + $val = rgget($name, $array); + return empty($val); +} +} + + +if(!function_exists("rgblank")){ +function rgblank($text){ + return empty($text) && strval($text) != "0"; +} +} + + +if(!function_exists("rgobj")){ +function rgobj($obj, $name){ + if(isset($obj->$name)) + return $obj->$name; + + return ''; +} +} \ No newline at end of file