コード例 #1
0
function AC_FetchMappedXProfileData($userID)
{
    // User data array
    $dataArray = array();
    // Need to query data in the BuddyPress extended profile table
    global $wpdb;
    // Generate table names
    $option_table = $wpdb->prefix . 'options';
    $xprofile_data_table = $wpdb->prefix . 'bp_xprofile_data';
    $xprofile_fields_table = $wpdb->prefix . 'bp_xprofile_fields';
    // Now, see which XProfile fields the user wants to sync.
    $sql = "SELECT option_name,option_value FROM {$option_table} WHERE option_name LIKE '" . WP88_BP_XPROFILE_FIELD_MAPPING . "%' AND option_value != '" . WP88_IGNORE_FIELD_TEXT . "'";
    $fieldNames = $wpdb->get_results($sql, ARRAY_A);
    // Loop through each field that the user wants to sync and hunt down the user's
    // values for those fields and stick them into an array.
    foreach ($fieldNames as $field) {
        $optionName = AC_DecodeUserOptionName(WP88_BP_XPROFILE_FIELD_MAPPING, $field['option_name']);
        // Big JOIN to get the user's value for the field in question
        // Best to offload this on SQL than PHP.
        $sql = "SELECT name,value,type FROM {$xprofile_data_table} JOIN {$xprofile_fields_table} ON {$xprofile_fields_table}.id = {$xprofile_data_table}.field_id WHERE user_id = {$userID} AND name = '{$optionName}' LIMIT 1";
        $results = $wpdb->get_results($sql, ARRAY_A);
        // Populate the data array
        if (!empty($results[0])) {
            $value = $results[0]['value'];
            // Now convert a checkbox type to a string
            if (0 === strcmp($results[0]['type'], "checkbox")) {
                $checkboxData = unserialize($value);
                $value = "";
                foreach ($checkboxData as $item) {
                    $value .= $item . ',';
                }
                $value = rtrim($value, ',');
            }
            $dataArray[] = array("name" => $optionName, "tag" => $field['option_value'], "value" => $value);
        }
    }
    return $dataArray;
}
コード例 #2
0
function AC_UpdateCampaignCategoryMappings()
{
    // Need to query data in the BuddyPress extended profile table
    global $wpdb;
    // Get this site's categories
    $categories = get_categories('hide_empty=0&orderby=name');
    // Data counter
    $counter = 1;
    $newIndex = 0;
    // Pull all of the mappings from the DB and update the option name.  There
    // will be only one row for each category, so an index of 0 is safe.
    $options_table_name = $wpdb->prefix . 'options';
    $sql = "SELECT option_name,option_value FROM {$options_table_name} WHERE option_name LIKE '" . WP88_CATEGORY_LIST_MAPPING . "%' ORDER BY option_name";
    $fields = $wpdb->get_results($sql);
    if ($fields) {
        foreach ($fields as $field) {
            $data = AC_DecodeUserOptionName(WP88_CATEGORY_LIST_MAPPING, $field->option_name);
            $catInfo = explode('&', $data);
            // Set a suffix.  Will be either "list", "group", or "template".  The
            // original mapping didn't include "list".
            $suffix = '_list';
            if (isset($catInfo[1])) {
                $suffix = "_{$catInfo['1']}";
            }
            // Inefficient, but done once.  This is necessary because AutoChimp
            // foolishly used to store the category name instead of slug in the
            // option_name.  So, this code looks up the category by name and
            // finds the slug and writes that.
            foreach ($categories as $category) {
                // Look for a match.
                if (0 === strcmp($catInfo[0], $category->name)) {
                    // Generate the new name and save it.
                    $newName = AC_EncodeUserOptionName(WP88_CATEGORY_MAPPING_PREFIX, $newIndex . $suffix);
                    update_option($newName, $field->option_value);
                    AC_Log("Migrated {$field->option_value} from {$field->option_name} to {$newName}.");
                    // Note that in 2.02 and earlier, there were three rows per
                    // mapping.  This needs to be translated into the new four
                    // rows per mapping.  So, when "_list" is encountered, just
                    // take the time to write out "_category" too.
                    if (0 === strcmp($suffix, '_list')) {
                        $newName = AC_EncodeUserOptionName(WP88_CATEGORY_MAPPING_PREFIX, $newIndex . '_category');
                        update_option($newName, $category->slug);
                        AC_Log("Migrated {$category->slug} from {$field->option_name} to {$newName}.");
                    }
                }
            }
            // Update this every three passes.
            if (0 == $counter % 3) {
                $newIndex++;
            }
            $counter++;
        }
    }
    // Now delete the old rows.
    $sql = "DELETE FROM {$options_table_name} WHERE option_name LIKE '" . WP88_CATEGORY_LIST_MAPPING . "%'";
    AC_Log("About to delete rows with this statement:  {$sql}");
    $numRows = $wpdb->query($sql);
    if (0 < $numRows) {
        AC_Log("Deleted {$numRows} from the {$options_table_name} table.");
    } else {
        AC_Log("No rows were found.  Nothing deleted.");
    }
}
コード例 #3
0
ファイル: SyncCimy.php プロジェクト: isrealconsulting/site
 public function FetchMappedData($userID)
 {
     // User data array
     $dataArray = array();
     // Special array for pain-in-the-axe checkboxes.
     $checkboxArray = array();
     // Need to query data in the Cimy tables
     global $wpdb;
     // Generate table names - options table tells us what mappings to pay attention to.
     $option_table = $wpdb->prefix . 'options';
     $cimy_data_table = $wpdb->prefix . 'cimy_uef_data';
     $cimy_fields_table = $wpdb->prefix . 'cimy_uef_fields';
     // Now, see which Cimy fields the user wants to sync.
     $sql = "SELECT option_name,option_value FROM {$option_table} WHERE option_name LIKE '" . WP88_CIMY_FIELD_MAPPING . "%' AND option_value != '" . WP88_IGNORE_FIELD_TEXT . "'";
     //	print "<br/>SQL to fetch field names: $sql";
     $fieldNames = $wpdb->get_results($sql, ARRAY_A);
     // Loop through each field that the user wants to sync and hunt down the user's
     // values for those fields and stick them into an array.
     foreach ($fieldNames as $field) {
         $optionName = AC_DecodeUserOptionName(WP88_CIMY_FIELD_MAPPING, $field['option_name']);
         // Big JOIN to get the user's value for the field in question
         // Best to offload this on SQL than PHP.
         $sql = "SELECT {$cimy_fields_table}.NAME,{$cimy_data_table}.VALUE,TYPE FROM {$cimy_data_table} JOIN {$cimy_fields_table} ON {$cimy_fields_table}.ID = {$cimy_data_table}.FIELD_ID WHERE USER_ID = {$userID} AND NAME = '{$optionName}' LIMIT 1";
         //		print "<br/>SQL to fetch data: $sql";
         $results = $wpdb->get_results($sql, ARRAY_A);
         // Populate the data array
         if (!empty($results[0])) {
             $value = $results[0]['VALUE'];
             // Do conversions based on field type
             // First, convert a timestamp to a date.  Without this code,
             // the month and day comes through fine, but the year is in
             // the year 4000 or something.  Low priority - look into this.
             if (0 === strcmp($results[0]['TYPE'], "registration-date")) {
                 $value = date("Y-m-d", $value);
             }
             // If it's a checkbox, do some special work.  This code exists because of
             // how CIMY does checkboxes.  Each integration with a 3rd party plugin is
             // a pain and this is CIMY's.  Basically, in order to properly send checkboxes
             // over to Mailchimp, we need to assemble them in to the same merge variable.
             if (0 === strcmp($results[0]['TYPE'], "checkbox")) {
                 // Change the name from upper case to lower case, then capitalize the
                 // first words. This is the only reasonably easy way to match CIMY
                 // field names to values required by MailChimp.  The rule that I am forced
                 // to create is that the MailChimp checkbox value must have each word
                 // capitalized.  So, this is reconstructed here.  CIMY doesn't store
                 // spaces (pain #1) and it capitalizes everything (pain #2).  I can see no
                 // need for the second one (the one that's a real pain).
                 $name = strtolower($results[0]['NAME']);
                 $name = str_replace('_', ' ', $name);
                 $name = ucwords($name);
                 // Do additional work if the checkbox is checked (value will be 'YES')
                 if (0 == strcmp($value, 'YES')) {
                     // Have this funky loop here to update elements in the "value" key of
                     // the array.  This is how MailChimp expects checkboxes to be set:
                     // with comma-separated strings representing the correct values that
                     // you set up in MailChimp.
                     $found = FALSE;
                     // Loop through each element in the checkbox array - note the reference
                     // (&) because we will be updating the value, not just reading it.
                     foreach ($checkboxArray as &$cba) {
                         // If the same tag is found already, it means we need to ADD it
                         // to the EXISTING hash.  The value that MailChimp expects is
                         // stored in the "NAME" - Remember, that's because of these
                         // artificial rules created to work around the limitations of CIMY.
                         if (in_array($field['option_value'], $cba)) {
                             // Mark it as found so that it's not added twice.
                             $found = TRUE;
                             // Update the value.
                             $cba['value'] = $cba['value'] . ",{$name}";
                         }
                     }
                     // If not found, it's a new set of checkboxes (or, more likely,
                     // it's the first element).
                     if (!$found) {
                         $cba = array("name" => $optionName, "tag" => $field['option_value'], "value" => $name);
                         $checkboxArray[] = $cba;
                     }
                 }
             } else {
                 $dataArray[] = array("name" => $optionName, "tag" => $field['option_value'], "value" => $value);
             }
         }
     }
     // Finally, in finishing up with the CIMY specific stuff, add the consolidated
     // checkbox data into the data array.
     if (!empty($checkboxArray)) {
         foreach ($checkboxArray as $cba) {
             $dataArray[] = $cba;
         }
     }
     return $dataArray;
 }
コード例 #4
0
 public function FetchMappedData($userID)
 {
     // User data array
     $dataArray = array();
     // Need to query data in the Wordpress options table
     global $wpdb;
     // Generate table names
     $optionTable = $wpdb->prefix . 'options';
     // Now, see which custom fields the user wants to sync.
     $sql = "SELECT option_name,option_value FROM {$optionTable} WHERE option_name LIKE '" . AUTOCHIMP_WISHLIST_MEMBER_DB_FIELD_MAPPING . "%' AND option_value != '" . WP88_IGNORE_FIELD_TEXT . "'";
     $fieldNames = $wpdb->get_results($sql, ARRAY_A);
     // Get the stored data and unserialize it
     $optionTable = $wpdb->prefix . 'wlm_user_options';
     $sql = "SELECT option_value FROM {$optionTable} WHERE user_id={$userID} AND option_name='wpm_useraddress'";
     $unserialized = $wpdb->get_var($sql);
     $data = unserialize($unserialized);
     // And finally, get the user data for each field name.
     foreach ($fieldNames as $field) {
         if ($this->FilterUnusedFields($field['option_name'])) {
             continue;
         }
         $optionName = AC_DecodeUserOptionName(AUTOCHIMP_WISHLIST_MEMBER_DB_FIELD_MAPPING, $field['option_name']);
         $value = $data[$optionName];
         $dataArray[] = array("name" => $optionName, "tag" => $field['option_value'], "value" => $value);
     }
     AC_Log($dataArray);
     return $dataArray;
 }
コード例 #5
0
 public function FetchMappedData($userID)
 {
     // User data array
     $dataArray = array();
     // Need to query data in the WordPress options table
     global $wpdb;
     // Generate table names
     $optionTable = $wpdb->prefix . 'options';
     // Now, see which WP-Members fields the user wants to sync.
     $sql = "SELECT option_name,option_value FROM {$optionTable} WHERE option_name LIKE '" . WP_MEMBERS_FIELD_DB_MAPPING . "%' AND option_value != '" . WP88_IGNORE_FIELD_TEXT . "'";
     $fieldNames = $wpdb->get_results($sql, ARRAY_A);
     // Get the stored data
     $metadata = get_metadata('user', $userID);
     // And finally, get the user data for each field name.
     foreach ($fieldNames as $field) {
         $optionName = AC_DecodeUserOptionName(WP_MEMBERS_FIELD_DB_MAPPING, $field['option_name']);
         // The data is in the 0th element of an array belonging to the hash.
         $value = $metadata[$optionName][0];
         $dataArray[] = array("name" => $optionName, "tag" => $field['option_value'], "value" => $value);
     }
     return $dataArray;
 }