function test_guid4href() { $test_guid = 'test-guid-does-not-matter'; $test_href = 'http://testdomain.com/test/path/' . $test_guid; $guid = SDKWrapper::guid4href($test_href); $this->assertEquals($guid, $test_guid); }
/** * Returns data used to build select menu of users that can be set as a distributor for a post * * @since 0.0.1 */ function _pmp_dist_option_select_distributor_for_post($post) { $ret = array('default_guid' => get_option('pmp_default_distributor', false), 'type' => 'distributor'); $sdk = new SDKWrapper(); $pmp_things = $sdk->query2json('queryDocs', array('profile' => 'user', 'limit' => 9999)); $pmp_things['items'] = array_filter($pmp_things['items'], function ($item) { if ($item['attributes']['guid'] !== pmp_get_my_guid()) { return $item; } }); $pmp_guid = get_post_meta($post->ID, 'pmp_guid', true); $pmp_doc = $sdk->query2json('fetchDoc', $pmp_guid); $existing_distributors = $pmp_doc['items'][0]['links']['distributor']; $existing_options = array(); if (!empty($existing_distributors)) { foreach ($existing_distributors as $distributor) { $distributor->guid = $sdk->guid4href($distributor->href); array_push($existing_options, $distributor); } } $existing_guids = array_map(function ($item) { return $item->guid; }, $existing_options); $settings = get_option('pmp_dist_settings'); $default_guids = $settings['pmp_dist_default_distributor']; if (!empty($pmp_things['items'])) { foreach ($pmp_things['items'] as $thing) { $thing_guid = $thing['attributes']['guid']; if (in_array($thing_guid, $existing_guids) || empty($existing_guids) && in_array($thing_guid, $default_guids)) { $selected = true; } else { $selected = false; } if (empty($existing_guids) && in_array($thing_guid, $default_guids)) { $title = $thing['attributes']['title'] . ' (default)'; } else { $title = $thing['attributes']['title']; } $option = array('selected' => $selected, 'guid' => $thing['attributes']['guid'], 'title' => $title); $options[] = $option; } } $ret['options'] = $options; return $ret; }
/** * Make sure distributor-set collections are preserved when pushing to the PMP * * @since 0.0.1 */ function pmp_dist_preserve_distributor_collection($doc, $previous_collection, $post) { $current_guids = array_map(function ($item) { return SDKWrapper::guid4href($item->href); }, $doc->links->collection); $previous_guids = array_map(function ($item) { return SDKWrapper::guid4href($item->href); }, $previous_collection); $difference = array_diff($previous_guids, $current_guids); if (!empty($difference)) { $sdk = new SDKWrapper(); foreach ($difference as $idx => $guid_to_check) { $collection = $sdk->fetchDoc($guid_to_check); foreach ($doc->links->distributor as $distributor) { if ($distributor->href == $collection->links->owner[0]->href) { $doc->links->collection[] = $previous_collection[$idx]; } } } } return $doc; }