Example #1
0
function mybb_import_attachment($source)
{
	global $convert_row, $convert;

	$target = phpbb_user_id($convert_row['uid']) . '_' . md5(unique_id());
	import_attachment($source, $target);

	if (mybb_has_thumbnail($convert_row['thumbnail']))
	{
		_import_check('upload_path', $convert_row['thumbnail'], 'thumb_' . $target);
	}

	return $target;
}
function get_location_attributes($post = null, $force = false)
{
    if (!$post instanceof WP_Post) {
        $post = get_post($post);
    }
    $codenum = get_location_meta($post->ID, 'name');
    if (!$force && ($location_attribute_meta = get_post_meta($post->ID, 'uw-location-attributes', true))) {
        return;
    }
    $room_import = json_decode(file_get_contents("http://www.cte.uw.edu/room/" . urlencode($codenum) . "?json"), true);
    wp_set_object_terms($post->ID, NULL, 'location-attributes');
    wp_set_object_terms($post->ID, NULL, 'location-type');
    foreach (array('instructions', 'schematic') as $type) {
        if (isset($room_import["{$type}_url"])) {
            import_attachment($type, $room_import["{$type}_url"]);
        }
    }
    if ($term = term_exists('Classroom', 'location-type')) {
        $classroom_term_id = intval($term['id']);
    }
    if (!($term = term_exists($room_import['room_type'], 'location-type'))) {
        $term = wp_insert_term($room_import['room_type'], 'location-type', array('parent' => $classroom_term_id));
    }
    wp_set_object_terms($post->ID, intval($term['term_id']), 'location-type', true);
    add_all_parent_terms('location-type', $post->ID);
    foreach ($room_import['attribute_list'] as $section => $attributes) {
        $section = trim($section);
        if (!($term = term_exists($section, 'location-attributes'))) {
            continue;
        }
        $section_id = intval($term['term_id']);
        wp_set_object_terms($post->ID, $section_id, 'location-attributes', true);
        foreach ($attributes as $attribute => $properties) {
            $attribute = trim($attribute);
            if (empty($attribute)) {
                continue;
            }
            if ($attr = term_exists($attribute, 'location-attributes')) {
                wp_update_term($attr['term_id'], 'location-attributes', array('parent' => $section_id));
            } else {
                if (is_wp_error($attr = wp_insert_term($attribute, 'location-attributes', array('parent' => $section_id)))) {
                    die(__FILE__ . ":" . __LINE__ . ' ' . $attr->get_error_message());
                }
            }
            wp_set_object_terms($post->ID, intval($attr['term_id']), 'location-attributes', true);
            foreach ($properties as $property => $value) {
                $location_attribute_meta[$attr['term_id']][$property] = $properties[$property];
            }
        }
    }
    if (count($location_attribute_meta)) {
        update_post_meta($post->ID, 'uw-location-attributes', $location_attribute_meta);
        update_post_meta($post->ID, 'uw-location-attributes-time', $_SERVER['REQUEST_TIME']);
    }
}